1.

How Can We Restrict Generics To A Super Class Of Particular Class?

Answer»

In MyListGeneric, Type T is defined as part of class declaration. Any JAVA Type can be used a type for this class. If we WOULD WANT to RESTRICT the types allowed for a Generic Type, we can use a Generic Restrictions. In declaration of the class, we specified a constraint "T super Number". We can use the class MyListRestricted with any class that is a super class of Number class.

In MyListGeneric, Type T is defined as part of class declaration. Any Java Type can be used a type for this class. If we would want to restrict the types allowed for a Generic Type, we can use a Generic Restrictions. In declaration of the class, we specified a constraint "T super Number". We can use the class MyListRestricted with any class that is a super class of Number class.



Discussion

No Comment Found