Java common classes how to instantiate

I have the following class structure:

public abstract class Generic<T extends SuperClass>

public class SuperGeneric<T extends SuperClass & SomeInterface> 
    extends Generic<T>

Now I want to make an instance SuperGenericcovering all possible classes. I tried this as follows:

Generic<? extends SuperClass & SomeInterface> myGeneric 
    = new SuperGeneric<? extends SuperClass & SomeInterface>();

Now it does not work. On Genericit gives the following error Incorrect number of arguments for type Generic<T>; it cannot be parameterized with arguments <? extends SuperClass, SomeInterface>.

And new SuperGenericI get the same error: Incorrect number of arguments for type SuperGeneric<T>; it cannot be parameterized with arguments <? extends SuperClass, SomeInterface>.

Any idea how to instantiate this properly SuperGeneric?

The idea is that I have two different classes that satisfy the condition extends SuperClass & SomeInterface, but they cannot be generalized by the same type.

+3
source share
2 answers

, . , , . , Type1 Type2.

:

Generic<Type1> myGeneric1 = new SuperGeneric<Type1>();

Generic<Type2> myGeneric2 = new SuperGeneric<Type2>();

. : ( )

+2

.

+2

All Articles