Op Sun, 02 Sep 2012 02:16:21 +0200 schreef Roedy Green
<see_w...@mindprod.com.invalid>:
> If Java were to be extended so you could call Iterator.remove inside a
> for:each, what sort of syntax might you use?
First let's establish that any such new syntax would not apply when
iterating over an array (cause a compile-time error).
A new keyword "remove" could be introduced:
for (E e : c)
remove;
In case of nesting, I guess this keyword should be defined as to remove
the current item from the Iterator belonging to the most deeply nested
for:each block in the current scope.
for (V v : foo)
for (K k : v.bar())
remove; // removes k, not v
Another extended syntax would be needed if you want to be able to
explicitly select an iterator:
for (V v : foo : Iterator<V> vi)
for (K k : v.bar())
if (k.isBaz(v)) {
vi.remove();
break;
}
--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/