RFR: 8266571: Sequenced Collections

Tagir F. Valeev tvaleev at openjdk.org
Fri Mar 24 22:28:50 UTC 2023


On Thu, 3 Nov 2022 00:49:52 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> @stuart-marks What are examples of cases where it wouldn't be reasonable: https://github.com/openjdk/jdk/pull/7387/files#diff-2b261a88d9ed30893d24186a36ef500d284d82e8f345591fc6c44ed5ae15da4fR161 ?
>
> I had to uncomment that line to figure out what broke. :-) Turns out `TreeSet.reversed().reversed()` doesn't return the original TreeSet. This is because `descendingSet().descendingSet()` doesn't unwrap, and neither does TreeMap's `descendingMap().descendingMap()`. I don't know what this wasn't done in the first place. Nonetheless, since unwrapping isn't done in the underlying implementation, it doesn't seem reasonable for the specification to require it be done. Furthermore this enables `reversed()` to be implemented as a default method that simply delegates to the respective `descending*()` method.

Also, `unmodifiableSequencedCollection(c).reversed().reversed()` does not return the original `unmodifiableSequencedCollection(c)`. And we probably cannot even specify that `x.reversed().reversed().equals(x)`, due to lack of `equals()` specification for all collections (in particular, Deques)...

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

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



More information about the client-libs-dev mailing list