title: Java: why can't iterate over an iterator?
body: <p>I read <a href="https://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable">Why is Java&#39;s Iterator not an Iterable?</a> and <a href="https://stackoverflow.com/questions/27240/why-arent-enumerations-iterable">Why aren&#39;t Enumerations Iterable?</a>, but I still don't understand why this:</p>
  
  <pre><code>void foo(Iterator&lt;X&gt; it) {
    for (X x : it) {
      bar(x);
      baz(x);
    }
  }
  </code></pre>
  
  <p>was not made possible. In other words, unless I'm missing something, the above could have been nice and valid syntactic sugar for:</p>
  
  <pre><code>void foo(Iterator&lt;X&gt; it) {
    for (X x; it.hasNext();) {
      x = it.next();
      bar(x);
      baz(x);
    }
  }
  </code></pre>