title: Multiway tree comparable interface issue
body: <p>I am creating a generic multiway tree which I KNOW will take only one of four types (Integer, Double, String and Character). I am having problems with the comparable interface and my insert function. Here is the relevant code I have written so far:</p>
  
  <pre><code>public class BTree&lt;T extends Comparable&lt;? super T&gt;&gt;
  {
      private int m=0, height=0, numkeys=0;
      private BTreeNode&lt;T&gt; root;
      boolean ready=false;
  
  class BTreeNode&lt;T extends Comparable&lt;? super T&gt;&gt;
  {
      boolean leaf = true;
      int keyTally = 1;
      Comparable&lt;T&gt; keys[] = new Comparable[m-1];
      BTreeNode&lt;T&gt; references[] = new BTreeNode[m];
      BTreeNode( T key)
      {
          keys[0] = (Comparable&lt;T&gt;) key;
          for ( int i=0; i&lt;m; i++)
              references[i] = null;
      }
  }
  
  public BTree( int c)
  {
      root=null;
      m=c;
  }
  
  // Not finished - can't test due to other bug
  public boolean insertElement( T elem)
  {
      insert( elem, root, height);
      numkeys++;
      return true;
  }
  
  // And now the ploblem function
  
  private BTreeNode&lt;T&gt; insert( T elem, BTreeNode&lt;T&gt; node, int hvar)
  {
      int i;
  
      BTreeNode&lt;T&gt; temp = null;
  
      if (hvar == 0)
      {
          for (i = 0; i &lt; node.keyTally; i++)
              if ( elem.compareTo(node.keys[i]) &lt; 0)
                  break;
      }
      else
      {
          for (i = 0; i &lt; node.keyTally; i++)
          {
              if ((i+1 == node.keyTally) || elem.compareTo(node.keys[i]) &lt; 0)
              {
                  Node n = insert( elem, node.references[i++], hvar-1);
                  if (n == null)
                      return null;
  
                  temp.keys[0] = n.keys[0];
                  temp.references[0] = n;
                  break;
              }
          }
      }
  
      for (int j = node.keyTally; j &gt; i; j--)
          node.keys[j] = node.keys[j-1];
      node.children[i] = temp;
      node.keyTally++;
      if (node.keyTally &lt; m)
          return null;
      else
      {
          BTreeNode&lt;T&gt; newNode = null;
          newNode.keyTally = m/2;
          for( i=0; i&lt;m/2; i++)
          newNode.references[i] = node.references[m/2+i];
          return newNode;
      }
      return null;
  }
  </code></pre>
  
  <p>And here is my console output:</p>
  
  <pre><code>BTree.java:169: error: method compareTo in interface Comparable&lt;T#2&gt; cannot be applied
  to given types;
  if ( elem.compareTo(node.keys[i]) &lt; 0)
           ^
  required: CAP#1
  found: Comparable&lt;T#1&gt;
  reason: actual argument Comparable&lt;T#1&gt; cannot be converted to CAP#1 by method
  invocation conversion
  where T#1,T#2 are type-variables:
  T#1 extends Comparable&lt;? super T#1&gt; declared in class BTree
  T#2 extends Object declared in interface Comparable
  where CAP#1 is a fresh type-variable:
  CAP#1 extends Object super: T#1 from capture of ? super T#1
  
  BTree.java:176: error: method compareTo in interface Comparable&lt;T#2&gt; cannot be
  applied to given types;
  if ((i+1 == node.keyTally) || elem.compareTo(node.keys[i]) &lt; 0)
                                    ^
  required: CAP#1
  found: Comparable&lt;T#1&gt;
  reason: actual argument Comparable&lt;T#1&gt; cannot be converted to CAP#1 by
  method invocation conversion
  where T#1,T#2 are type-variables:
  T#1 extends Comparable&lt;? super T#1&gt; declared in class BTree
  T#2 extends Object declared in interface Comparable
  where CAP#1 is a fresh type-variable:
  CAP#1 extends Object super: T#1 from capture of ? super T#1
  
  BTree.java:178: error: cannot find symbol
  Node n = insert( elem, node.references[i++], hvar-1);
  ^
  symbol:   class Node
  location: class BTree&lt;T&gt;
  where T is a type-variable:
  T extends Comparable&lt;? super T&gt; declared in class BTree
  
  BTree.java:191: error: cannot find symbol
  node.children[i] = temp;
      ^
  symbol:   variable children
  location: variable node of type BTree&lt;T&gt;.BTreeNode&lt;T&gt;
  where T is a type-variable:
  T extends Comparable&lt;? super T&gt; declared in class BTree
  
  Note: Some input files use unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  4 errors
  </code></pre>
  
  <p>I don't understand what I am doing wrong with the comparable interface to make it complain about the compareTo method. Additionally, I was wondering what it will do if the string type is used? I assume it will just see which one comes first in order alphabetically. Thanks :)</p>