title: How to create an array with Iterable elements in Java?
body: <p>I want to create an array which its length is <strong>fixed</strong>, but the elements are reference to <code>Iterable</code> objects. Just like creating an array with pointer elements in C, where the pointers can point to lists of any length.</p>
  
  <p>I tried this:</p>
  
  <pre><code>// declaration
  private Iterable&lt;String&gt;[] a;
  ...
  // in construtor, n is known length.
  a = (Iterable&lt;String&gt;[]) new Object[n];
  </code></pre>
  
  <p>The compiler gives me a warning. And when I execute the program. the exception below is thrown.</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: 
  [Ljava.lang.Object; cannot be cast to [Ljava.lang.Iterable;
  </code></pre>
  
  <p>I searched through the web. But the results are all <strong>dynamic array</strong> but not <strong>fixed-length array with dynamic elements</strong>. Thanks a lot if you can help!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'll try to put it simpler. What I want is like an <strong>array of references</strong>, and the reference can point to some Iterable object.</p>