On Sat, 15 Oct 2022 07:30:54 GMT, Tagir F. Valeev <tval...@openjdk.org> wrote:

> For unsorted sets like LinkedHashSet, it's unclear how to behave if 
> replaceAll returns identical elements. Throw an exception? Shrink the set 
> size via deduplication?

I would assume the spec for replaceAll would be borrowed from 
Map.html#replaceAll(java.util.function.BiFunction).  Shrinking size is not an 
option because that is a ConcurrentModificationException.  Adding elements to 
the set would a ConcurrentModificationException.  Therefore, 
LinkedHashSet::replaceAll would have to be swapping the order of the linked 
entries already contained in the set.  So in your example of returning 
identical elements the answer is CCE (or IAE) if the element is not contained 
in the set.  Otherwise, the element is eventually moved to the last entry in 
the set.

-------------

PR: https://git.openjdk.org/jdk/pull/10520

Reply via email to