0

Bellow is a class for Binary search tree.

class BinarySearchTree <T extends Comparable<T>> implements Iterable<T> {
    private Node<T> root;
    public void add(T data) {
        Node<T> p = new Node<T>(data);
        if (root == null) {
            root = p;
        } else {
            root.addNode(p);
        }
   }

Why is the Comparable extended instead of implemented? for example

class BinarySearchTree <T> implements Iterable<T>, Comperable <T>
Max K
  • 71
  • 1
  • 11
  • 2
    In generic type bounds, you use `extends` both both classes and interfaces. – Eran Apr 09 '18 at 11:48
  • @Eran so I see that T has to extend Comparable and whole class has to implement methods of Iterable. Is that right? – Max K Apr 09 '18 at 11:56

0 Answers0