title: Java Generics Test class
body: <p>Im new to generics and i have to implement a binary search tree using generics. I did that but now im wondering how do i test the code that i wrote? Do i just make another class and start using the methods of the bst?</p>
  
  <p>any help would be appreciated. below is my code just to clarify.</p>
  
  <pre><code>public class BST&lt;E extends Comparable&lt;E&gt;&gt;
  {
  public Node&lt;E&gt; root;
  
  
  public BST()
  {
      root = null;
  }
  //insert delete find height
  public void find(E s, Node&lt;E&gt; n)
  {
      //empty tree, root is null
      if(n == null)
      {
          System.out.println("Item not present.");
      }
      //n is the node where s is, return n
      else if(n.getData().equals(s))
      {
          System.out.println("Item present");
      }
      //s is greater than n, look for s on the right subtree
      else if(s.compareTo(n.getData()) &gt; 0)
      {
          find(s, n.getRight());
      }
      //s is less than n, look for s on the left subtree
      else
      {
          find(s, n.getLeft());
      }
  }
  
  public int height() 
  {
      int count;
      return count = height(root); 
  }
  
  private int height(Node&lt;E&gt; n)
  {
      int ct = 0;
      if(n == null)
      {
  
      }
  
      else
      {
  
          int left = height(n.getLeft());
  
          int right = height(n.getRight());
  
          ct = Math.max(left, right) + 1;
      }
      return ct;
  } 
  
  public void insert(E s) 
  {
      root = insert(s, root);
  } 
  
  private Node&lt;E&gt; insert(E s, Node&lt;E&gt; T)
  {
      //easiest case, empty tree, create new tree
      if(T == null)
      {
          T = new Node&lt;E&gt;(s,null,null);
      }
      //easiest case, found s
      else if(s.compareTo(T.getData()) == 0)
      {
          System.out.println("Item already present.");
      }
      //s is greater than T, insert on right subtree
      else if(s.compareTo(T.getData()) &gt; 0)
      {
          T.setRight(insert(s, T.getRight()));
      }
      //s is less than T, insert on left subtree
      else
      {
          T.setLeft(insert(s,T.getLeft()));
      }
      return T;
  }
  
  public void delete(E d)
  {
  }
  
  }
  </code></pre>
  
  <p>and my node class</p>
  
  <pre><code>public class Node&lt;E&gt; 
  {
     private E data;
  private Node&lt;E&gt; left;
  private Node&lt;E&gt; right;
  private Node&lt;E&gt; parent;
  
     public  Node(E d, Node&lt;E&gt; r, Node&lt;E&gt; l) 
  {
    data = d;
  
      left = l;
      right = r; 
     }
     public void setData(E d) 
  {
    data = d;
     }
  public E getData()
  {
      return data;
  }
     public Node&lt;E&gt; getRight() 
  {
    return right;
     }
  public void  setRight(Node&lt;E&gt; nd)
  {
      right = nd;
  }
     public Node&lt;E&gt; getLeft()
  {
      return left;
  }
  public void  setLeft(Node&lt;E&gt; nd)
  {
      left = nd;
  }
  public Node&lt;E&gt; getParent()
  {
      return parent;
  }
  public void  setParent(Node&lt;E&gt; nd)
  {
      parent = nd;
  }
  }
  </code></pre>
  
  <p>Im trying to follow what you said, this is my test class
      public class BSTTest
          {
          public void testInsert()
          {
          int height;
          BST myTree = new BST();
          myTree.insert(1);
          }</p>
  
  <pre><code>} 
  </code></pre>
  
  <p>but when i compile i get the error of unexpected type, it says if found an int but requires a reference on the line of BST myTree = new BST(); what does that mean?</p>