Skip to content

Java generic arrays

In short, you can’t create generic arrays (i.e. new GenericType<T>[1] is not allowed) as doing so would give you a “Cannot create a generic array of …” error.

A quick work around is to create a generic list instead of the generic array. So the example above can be instanced as new List<GenericType<T>>

Posted in Java. Tagged with , , , .