I have the following class structure:
public abstract class Generic<T extends SuperClass>
public class SuperGeneric<T extends SuperClass & SomeInterface>
extends Generic<T>
现在我想创建一个覆盖所有可能类的
SuperGeneric
实例。我尝试了以下方法:Generic<? extends SuperClass & SomeInterface> myGeneric
= new SuperGeneric<? extends SuperClass & SomeInterface>();
现在似乎无法正常工作。 在“Generic”上它给出了以下错误:
Incorrect number of arguments for type Generic<T>; it cannot be parameterized with arguments <? extends SuperClass, SomeInterface>
。而在“new SuperGeneric”中,我得到了类似的错误:
Incorrect number of arguments for type SuperGeneric<T>; it cannot be parameterized with arguments <? extends SuperClass, SomeInterface>
。你知道如何正确创建这个“SuperGeneric”的实例吗?
我的想法是有2个不同的类符合“extends SuperClass & SomeInterface”条件,但这些不能被一个类型泛化。