Iterator.forEachRemaining and Iterator.remove
martinrb at google.com
Wed Oct 26 00:44:06 UTC 2016
I assigned this to Paul (hope that's OK)
Iterator.forEachRemaining vs. Iterator.remove
On Tue, Oct 25, 2016 at 4:13 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> > On 25 Oct 2016, at 15:16, Martin Buchholz <martinrb at google.com> wrote:
> > Actually, the ArrayList implementation updates fields only at the end of
> the iteration, so if an action throws in the middle, the iterator is
> semi-corrupted (in the sense that remove() will remove the "wrong" element
> and next will return previously visited elements).
> Good point.
> > I think it's best to say in the spec that after calling
> forEachRemaining, subsequent operations on the Iterator are undefined
> (whether or not the action throws).
> Yes (and for an action calling remove).
> > For consistency, we should probably keep the historic behavior that
> remove() after forEachRemaining() removes the last element, even though
> that is not to be encouraged.
More information about the core-libs-dev