title: How to avoid cast error generated by comparable interfaces
body: <p>I have a generics class in Java:</p>
  <pre><code>public class PriorityList&lt;T extends Number&gt; implements Comparable&lt;T&gt; {  
  
      T[] array = (T[]) new Object[10];
  </code></pre>
  <p>And I have an error</p>
  <blockquote>
  <p>java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Number;</p>
  </blockquote>
  <p>Error is make by this casting <strong>(T[]) new Object[10]</strong>.</p>
  <p>I need compare methods because I need the array elements must be sorted. So I can't declare class  like this</p>
  <pre><code>public class PriorityList&lt;T extends Number&gt; 
  </code></pre>
  <p>Other options which have some sense is make by my own linked list to keep T values. But is another way to solve this casting problem</p>
  <pre><code>(T[]) new Object[10];
  </code></pre>
  <p>?</p>
  <p>PS
  Collections are forbidden to use.</p>