From Lower Bounded Wildcards, a section of the Generics section of The Java Tutorial:
... a lower bounded wildcard restricts the unknown type to be a specific type or a super type of that type.
(bold mine, emphasis theirs)
Thus, the set of classes that match T extends Comparable<T>
is a subset of the set of classes that match T extends Comparable<? super T>
. The wildcard ? super T
itself matches T
and any superclasses of T
.
In other words, the assumption that "super
would only include super class items" is simply incorrect.
Your confusion in the example may also arise from the fact that JTextField
is a superclass of JPasswordField
; in other words, JPasswordField extends JTextField
. The example would match any of the 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 would make much more sense as the following:
void describeComponent(CustomComponent<? super JTextField> ref) {...}
Note that JPasswordField, which is a subclass of JTextField, itself is
omitted in the list of permissible objects, because it is not a
superclass of JTextField.