Here is one declaration
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> {
....
}
Here is the other declaration
public class BinarySearchTree<AnyType extends Comparable<AnyType>>{
.....
}
I know the first declaration is preferred(seen it in alot of java examples and textbooks) but why is that? All my code ran fine when I tried using the second declaration as well.
I know that super used in this context, ? super AnyType, means AnyType or any of its super classes. Super
To me both are saying that this class, BinarySearchTree, supports any object type that is comparable. Can anyone describe or give an example of where this subtle difference actually makes a difference?
With dog example
class Animal implements Comparable<Animal>
class Dog extends Animal
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> {
...}
Would allow for
BinarySearchTree<Dog> but
public class BinarySearchTree<AnyType extends Comparable<AnyType>>{
.....
} wouldn't