title: using compareTo in Binary Search Tree program
body: <p>I've been working on this program for a few days now and I've implemented a few of the primary methods in my BinarySearchTree class such as insert and delete. Insert seemed to be working fine, but once I try to delete I kept getting errors. So after playing around with the code I wanted to test my compareTo methods. I created two new nodes and tried to compare them and I get this  error:</p>
  
  <p>Exception in thread "main" java.lang.ClassCastException: TreeNode cannot be cast to java.lang.Integer
      at java.lang.Integer.compareTo(Unknown Source)
      at TreeNode.compareTo(TreeNode.java:16)
      at BinarySearchTree.myComparision(BinarySearchTree.java:177)
      at main.main(main.java:14)</p>
  
  <p>Here is my class for creating the nodes:</p>
  
  <pre><code>    public class TreeNode&lt;T&gt; implements Comparable
      {
          protected TreeNode&lt;T&gt; left, right;
          protected Object element;
  
      public TreeNode(Object obj)
      {
          element=obj;
          left=null;
          right=null;
      }
  
     public int compareTo(Object node)
     {
         return ((Comparable) this.element).compareTo(node);
     }
  </code></pre>
  
  <p>}</p>
  
  <p>Am I doing the compareTo method all wrong? I would like to create trees that can handle integers and strings (seperatly of course)</p>