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