I am trying to understand what is the purpose of using <? super T>
in generics in Java. I have read a lot, but haven't understood it yet. It is clearly for me using <T extends SomeClass>
, if the class is SomeClass or subclass of SomeClass we don't need to now exact type of subclass, we know only that it has methods of superclass SomeClass
, so we can invoke methods like T.someMethod();
It is very powerful feature. But I cannot understand purpose of using <T super SomeClass>
.
What privileges we have writing such wildcard? T is super class of SomeClass, so what Super class may doesn't have methods of SomeClass, we can only ensure that super class of SomeClass has all methods of Object so this becomes useless, so what is the purpose of using this?