On Wed, 19 Apr 2023 09:43:44 GMT, Nir Lisker <[email protected]> wrote:
>> Stuart Marks has updated the pull request incrementally with three
>> additional commits since the last revision:
>>
>> - Remove unnecessary 'final' from a couple places.
>> - Clarify ordering of Collection.addAll and Map.putAll; add links to
>> encounter order.
>> - Make constructors private for several reverse-ordered views.
>
> src/java.base/share/classes/java/util/SequencedCollection.java line 1:
>
>> 1: /*
>
> I wonder if there's a point to mention the relation of reversal to the
> "enhanced for-each" loop. The loop uses the iterator behind the scenes. That
> means that a reversed collection will iterate backwards in a loop ("enhanced
> each-for" loop :) ). A backwards iteration can be achieved by
>
> for (E element : collection.reversed()) {...}
>
> For collections that support removal, this construct can also be used to
> remove elements without the concurrent modification problem of removal during
> iteration which messes up the indices. See, for example,
> https://stackoverflow.com/questions/10431981/remove-elements-from-collection-while-iterating.
Can't remove using the iterator since it's hidden, and can't remove directly
from the collection during iteration without potentially suffering CME. The
reverse-iteration trick for removal generally only works for index-based
iteration. Not sure what would be useful to add here.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1171694499