title: Java Generics in a Binary Tree, incompatible types error
body: <p>I'm trying to implement a Binary Tree in java with Generics, i searched and i find this question: <a href="https://stackoverflow.com/questions/27155596/implementing-binary-tree-in-java-with-generic-comparablet-data">Implementing Binary Tree in Java with Generic Comparable&lt;T&gt; data?</a>, but i couldn't resolve my doubts. So i have two classes, </p>
  
  <pre><code>BST_Tree&lt;T&gt; 
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Node&lt;T extends Comparable&lt;T&gt;&gt; 
  </code></pre>
  
  <p>I want that my implementation can:</p>
  
  <ol>
  <li><p>Take every type of Object and put it inside the field <code>key</code> in Node</p></li>
  <li><p>Compare every node with the <code>key</code> field</p></li>
  </ol>
  
  <p>This is the code:</p>
  
  <pre><code>public class Node &lt; T extends Comparable &lt; T &gt;&gt; {
  
      private T key;
      private Node left;
      private Node right;
      private Node p;
  
      public void setKey(T key) {
          this.key = key;
      }
  
      public T getKey() {
          return key;
      }
  
      public Node getLeft() {
          return left;
      }
  
      public Node getRight() {
          return right;
      }
  
      public void setLeft(Node left) {
          this.left = left;
      }
  
      public void setRight(Node right) {
          this.right = right;
      }
  
      public void setP(Node p) {
          this.p = p;
      }
  
      public boolean getBolCompMin(T key) {
          return this.key.compareTo(key) &lt; 0;
      }
  }
  </code></pre>
  
  <p>My Node class is suppose to extend <code>Comparable</code> in order to compare the key.</p>
  
  <p>This is my tree:</p>
  
  <pre><code>public class BST_Tree &lt; T &gt; {
  
      private ArrayList &lt; Node &gt; nodes;
      private Node root;
  
      public BST_Tree(Node root) {
          this.root = root;
      }
  
      public void insertNode(T key) {
          Node z = new Node();
          z.setKey(key);
          Node x = this.root;
          Node y = new Node();
  
          while (x != null) {
  
              y = x;
              if (z.getBolCompMin(x.getKey())) {
                  x = x.getLeft();
              } else {
                  x = x.getRight();
              }
          }
  
          z.setP(y);
  
          if (z.getBolCompMin(y.getKey())) {
              y.setLeft(z);
          } else {
  
              y.setRight(z);
          }
      }
      public void InOderWalk(Node x) {
          if (x != null) {
              InOderWalk(x.getLeft());
              System.out.println(x.getKey());
              InOderWalk(x.getRight());
          }
      }
  
      public Node getRoot() {
          return root;
      }
  }
  </code></pre>
  
  <p>My tree tries to set the key in node z but it fails. This is the error:</p>
  
  <blockquote>
    <p>incompatible types: T cannot be converted to java.lang.Comparable</p>
  </blockquote>
  
  <p>Thank you in advance!</p>