So I know that you cannot \"easily\" create an array of a generic type in Java (but you can create collections). I recently ran across a situation where I needed a 2 dimens
This will allow it to work (along with an unchecked cast, which is normal for this situation since you want to have a variable that is the array of a generic type). The solution is realizing that just Foo
refers to the parameterized class Outer
, since you are inside the scope of Outer
; and that to get the actual raw class, you need to explicitly qualify it as Outer.Foo
:
foo = (Foo[][])new Outer.Foo[width][height];