On Thu, 30 Mar 2023 09:20:16 GMT, Tagir F. Valeev <tval...@openjdk.org> wrote:

>> Stuart Marks has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Simplify handling of cached keySet, values, and entrySet views.
>
> src/java.base/share/classes/java/util/SequencedCollection.java line 78:
> 
>> 76:  * @since 21
>> 77:  */
>> 78: public interface SequencedCollection<E> extends Collection<E> {
> 
> Should we narrow the specification for `Collection::add` here, saying that 
> `add` is essentially `addLast`? Specification for deque mentions that `add` 
> and `addLast` are equivalent. Otherwise, the implementation of 
> `SequencedCollection::add` that adds the element to a random position will 
> comply the spec.
> 
> Another thing is `remove(Object)`. Should we specify here that it will remove 
> the first instance of Object inside the collection (like it's specified in 
> the list)? Or is it allowed to return a random one?

`add` isn't the same as `addLast` because things like `SortedSet.add` need to 
add the element in its proper place. The other subtypes `List`, `Deque`, and 
`LinkedHashSet` specify that added elements go at the end. But we can't rule 
out some new collection that might have some reasonable rule for adding a new 
element other than in the last position.

`List` and `Deque` specify that `remove` removes the first occurrence, but this 
doesn't apply to `LinkedHashSet` or `SortedSet` since they can have only one 
occurrence of a matching element. Thus we don't have any obvious examples. But 
somebody might come up with some new collection for which the first occurrence 
of duplicate elements isn't the right semantics, so I don't think we want to 
specify that here.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1167371303

Reply via email to