java - Why does T extends Comparable <? super T> include T? Meaning includes Comparable<T>? -
class binarysearch<t extends comparable<? super t> >
why t extends comparable <? super t>
including t
, meaning including comparable<t>
, not super class hierarchy? confused on super keyword thought super include super class items. new java , in java book had following example:
this regarding method in class trying limit upper , lower bound of hierarchy using java.awt.component class had extends container
class customcomponent<t extends container>
in class have following method
void describecomponent<customcomponent<? super jpasswordfield> ref)
and goes on
note jpasswordfield, superclass of jtextfield, omitted in list of permissible objects.
from lower bounded wildcards, section of generics section of the java tutorial:
... lower bounded wildcard restricts unknown type a specific type or super type of type.
(bold mine, emphasis theirs)
thus, set of classes match t extends comparable<t>
subset of set of classes match t extends comparable<? super t>
. wildcard ? super t
matches t
, superclasses of t
.
in other words, assumption "super
include super class items" incorrect.
your confusion in example may arise fact jtextfield
superclass of jpasswordfield
; in other words, jpasswordfield extends jtextfield
. example match of following classes:
- javax.swing.jpasswordfield
- javax.swing.jtextfield
- javax.swing.jtextcomponent
- javax.swing.jcomponent
- java.awt.container
- java.awt.component
- java.lang.object
the example make more sense following:
void describecomponent(customcomponent<? super jtextfield> ref) {...}
note jpasswordfield, subclass of jtextfield, omitted in list of permissible objects, because not superclass of jtextfield.
Comments
Post a Comment