how do I correctly write following class declaration in Java?
public class BinarySearchTree<T extends BinarySearchNode<E implements Comparable<E>>> implements Iterable<E>
Basically, I am trying to create a BinarySearchTree of any class T that inherits BinarySearchNode of a Comparable datatype E (And my BinarySearchTree should also be Iterable).
How can I properly declare that class in Java? Thanks!
Iterableon the values i.e.Einstead of on the node?E extends Comparable<E>forE extends Comparable<? super E>. This would allow you to have a tree of i.e.DogwithDogbeing a subclass ofAnimalandAnimalbeingComparable. I mean that you could use thecompareTomethod from one ancestor of the element type of your tree, and you shouldn't need to implementcompareToinDog(using the one fromAnimalwould suffice, if it's good enough).<E>to<? super E>. If you are interested on this topic, you should read about PECS.