You cannot create an array of generics, because arrays are covariant and generics are (normally) invariant. Combined with the fact that arrays are reified and generics are erased, this makes them incompatible that way -- the array can't store the actual generic type anymore. You can however have a generic parameterized with an array since java can check the cast.

You cannot create an array of a generic type, it's an inherent limitation (or perhaps restriction is a better term) of the compiler. If you do a google search for "array of arraylist" you'll see lots of people with the same question.

There are a couple of nasty workarounds:- use Array.newInstance() and cast the result- use ArrayList<ArrayList<Thing>>( size );

But you should probably consider a redesign that doesn't require you to 'mix' an array of lists.

I used to agree with you until I saw c++ templates. If you think type erasure is bad, just try to declare a generic variable in the global scope. fyi, you cannot. That sir, is what really sucks here. Give me type erasure any day.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org