I will dive quick to the problem. I have a straightforward class
class Vector{
float x, y;
}
and another class has an array of these objects as its member
Vector[] buffer;
I initialize it like this:
buffer = new Vector[8];
for(Vector v: buffer)
v = new Vector();
but when I try to access this objects' members in this array I get a NullPointerException straight to my stack trace. That is, objects of array have not been constructed. On the other hand this more traditional code works just perfect:
buffer = new Vector[8];
for(int i = 0; i<8; i++)
buffer[i] = new Vector;
As this discussion points it out, both should be the same after compilation.
My question is, why for each loop fails to initialize/construct objects from the item array?