I will quickly move on to the problem. I have a simple class
class Vector{ float x, y; }
and another class has an array of these objects as a member
Vector[] buffer;
I initialize it as follows:
buffer = new Vector[8]; for(Vector v: buffer) v = new Vector();
but when I try to access the elements of this object in this array, I get a NullPointerException directly to my stack trace. That is, array objects were not built. On the other hand, this more traditional code works just fine:
buffer = new Vector[8]; for(int i = 0; i<8; i++) buffer[i] = new Vector;
As this one discusses this, both should be the same after compilation.
My question is: why for each cycle it is not possible to initialize / build objects from an array of elements?
java syntax for-loop
mehmetminanc
source share