title: How to use compareTo within a Generic array in java?
body: <p>I am trying to figure out how to compare two items within a T[] array, here is what I have:</p>
  
  <pre><code>public static &lt;T extends Comparable&lt; ? super T&gt;&gt; T getLargest(T [] a, int low, 
                 int high){
      if(low&gt;high)
              throw new IllegalArgumentException();
      T[] arrCopy = (T[]) new Object[high-low];
      for(int i=low;i&lt;high;i++){
          if(a[i].compareTo(a[i-1])&gt;0)
              arrCopy[i]=a[i];
          else
              arrCopy[i]=a[i+1];
      }
      return arrCopy[0];
  }
  </code></pre>
  
  <p>and then I get the error: <code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;</code></p>
  
  <p>Any ideas on how I can resolve this?</p>