title: generic array of inner class initialization in java
body: <p>Is there any way to make the following code work in Java? </p>
  
  <pre><code>public class RandomizedQueue&lt;Item&gt; implements Iterable&lt;Item&gt; {  
      private static final int ARRAYSIZE = 8; // default array size
      private Node[] nodeArray;               // contains pointers to the randomized nodes    
      private int size;                       // current size of queue
  
      private class Node
      {
          private Item item;
          private Node next;
          private Node previos;
      }
  
      @SuppressWarnings("unchecked")
      public RandomizedQueue()           // construct an empty randomized queue
      {
          nodeArrays = (Node[]) new Object[ARRAYSIZE]; // fix this and everything works!
      }
  
      // unimportant randomized queue implementation details
      // ...
  }
  </code></pre>
  
  <p>It crashes on runtime at nodeArray initialization line with the following error:</p>
  
  <p><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LRandomizedQueue$Node;
      at RandomizedQueue.&lt;init&gt;(RandomizedQueue.java:18)
      at Subset.main(Subset.java:6)</code>.</p>
  
  <p>The problem is that I cannot use library data structures such as ArrayList&lt;>, because I got to have custom re-size rules. In addition, I cannot implement ArrayList analogue myself (no additional classes allowed in my task).</p>
  
  <p>Code <code>nodeArray = new Node[ARRAYSIZE];</code> does not compile in Eclipse with error <code>Cannot create a generic array of RandomizedQueue&lt;Item&gt;.Node</code>.</p>