It just wonβt compile in Java (because you assign an array type value to a type variable without a Foo array):
Foo foos = new Foo[12];
it is rejected by javac with the following error (see also: http://ideone.com/0jh9YE ):
test.java:5: error: incompatible types Foo foos = new Foo[12];
For it to compile, declare Foo as type Foo[] , and then just flip it:
Foo[] foo = new Foo[12]; # <<<<<<<<< for (int i = 0; i < 12; i += 1) { foos[i] = new Foo(); }
source share