title: Breadth First Binary Tree Search using TreeNodes Extending Comparable
body: <p>I'm having issues implementing my breadth first traversal for my binary tree. I keep getting a class cast exception at these two lines:</p>
  
  <pre><code>        if(node.left != null) queue.offer(node.left);
          if(node.right != null) queue.offer(node.right);
  </code></pre>
  
  <p>The exception says: "TreeNode cannot be cast to java.lang.Comparable" 
  I need the extends Comparable for other methods this class, any suggestions on how to fix this? Thanks!</p>
  
  <pre><code>public class TreeNode&lt;E extends Comparable&lt;E&gt;&gt; {
  
  private TreeNode&lt;E&gt; left;
  private TreeNode&lt;E&gt; right;
  private E value;
  
  
  public TreeNode(E value) 
  {
      this.value = value;
  }
  
      public void breadthFirstTraversal(TreeNode&lt;E&gt; root, ArrayList&lt;E&gt; breadthList)
  {
      Queue&lt;TreeNode&lt;E&gt;&gt; queue = new PriorityQueue&lt;TreeNode&lt;E&gt;&gt;();
      if (root == null)
          return;
      queue.clear();
      queue.offer(root);
      while(!queue.isEmpty())
      {
          TreeNode&lt;E&gt; node = queue.remove();
          breadthList.add(node.value);
          if(node.left != null) queue.offer(node.left);
          if(node.right != null) queue.offer(node.right);
      }
  }
  </code></pre>