I am trying out some examples to understand “extends” and “super” in relation to generics. I was wondering, why does this work;
But this does not:
Why is the second code syntax wrong?
Stephan van Hulst
posted 1 year ago
Because the language designers decided that upper bounds on type parameters weren't useful, and therefor should not be allowed. Using the extends keyword, you can put lower bounds on type parameters and wildcards, but you can put upper bounds only on wildcards (e.g. Comparator<? super T>).
Type parameters are mostly useful so you can return specific types. Using the super keyword would return less specific types, and so is not very useful.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.