Class<? super T> getSuperclass()
The getSuperclass() in Class class return a Class whose type is<? super T>, which mean that the type parameter of Class of the Super could be T or any of its Superclasses, now how come a SuperClass's Class type parameter be the same type as the subclass?
for example
Class<Manage>.class.getSuperclass()
doesn't return
Class<Manager>
at all ..like never
Does this make sense? or i am missing something here?
The bound is just a overly-broad because it's as close as you can express using Java's generics.
What you really want is <the immediate superclass of T>
; but there's no way to write that in Java's generics. There's also no way to write <? super T excluding T>
. <? super T>
is pretty much as specific as you can get given the way Java's generics work.
For what it's worth you can guarantee that the class you get back will be the superclass in question -- no matter what its type bound is.
There's no way with Java generics to specify "some superclass but not the class itself." So the provided bound is the best one you can possibly specify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With