title: for each loop cannot initialize objects in array
body: <p>I will dive quick to the problem. I have a straightforward class</p>
  
  <pre><code>class Vector{
      float x, y;
  }
  </code></pre>
  
  <p>and another class has an array of these objects as its member</p>
  
  <pre><code>Vector[] buffer;
  </code></pre>
  
  <p>I initialize it like this:</p>
  
  <pre><code>buffer = new Vector[8];
  for(Vector v: buffer)
      v = new Vector();
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>buffer = new Vector[8];
  for(int i = 0; i&lt;8; i++)
      buffer[i] = new Vector;
  </code></pre>
  
  <p>As <a href="https://stackoverflow.com/questions/85190/how-does-the-java-for-each-loop-work">this</a> discussion points it out, both should be the same after compilation.</p>
  
  <p>My question is, why for each loop fails to initialize/construct objects from the item array?</p>