You cannot create arrays of parametrized types, as stated in the Java SE tutorial
(...)You cannot create arrays of parameterized types.
For example, the following code does not compile:
List<Integer>[] arrayOfLists = new List<Integer>[2]; // compile-time error
The following code illustrates what happens
when different types are inserted into an array:
Object[] strings = new String[2];
strings[0] = "hi"; // OK
strings[1] = 100; // An ArrayStoreException is thrown.
If you try the same thing with a generic list, there would be a problem:
Object[] stringLists = new List<String>[]; // compiler error, but pretend it's allowed
stringLists[0] = new ArrayList<String>(); // OK
stringLists[1] = new ArrayList<Integer>(); // An ArrayStoreException should be thrown,
// but the runtime can't detect it.
If arrays of parameterized lists were allowed,
the previous code would fail to throw the desired ArrayStoreException.(...)
It has nothing to do with primitive types or objects, as you can see from the example below
public class Generics<T> {
T x;
public static void main(String[] args) {
Generics<byte[]> g = new Generics<byte[]>();
g.x = new byte[10];
g.x[1] = 1;
}
Generics<T>[] getMyArray(){
Generics<Byte[]>[] array = new Generics<Byte[]>[1]; <<<<error
}
}