I just learn up to tree and one thing I don’t understand about it is the class declaration:
for example: class BinarySearchTree<T extends Comparable<? super T>>.
Now, can you please explain me what is in the bracket and the “<? super T>“?
Any good source you can refer me to? Thanks.
This declares a class with a single generic type parameter. Since for the binary search tree it’s imperative that it can compare two items, this needs to be specified so that the compiler can verify it.
The part in angle brackets is the type parameter
Tand a constraint for it which says:Tis, it should extendComparable(<T extends Comparable<...>>).Comparableshould be able to compare itself to eitherTor a super-class ofT(<? super T>).Since
Tcould usually be anything this constrains the choice to types where it makes sense to implement a search tree for.