RFR: 8308694: Clarify reversed() default methods' implementation requirements

Stuart Marks smarks at openjdk.org
Thu Jun 15 23:50:05 UTC 2023


On Thu, 15 Jun 2023 22:54:09 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Can I get a preliminary review of the wording for Deque.reversed()? If the text is good, I'll make corresponding changes to the implSpecs of the other reversed() default methods, namely those in List, SortedMap, and SortedSet and then file the CSR.
>
> Reads well.

@bplb OK thanks. But now that I've posted this, I'm having second thoughts. :-)

The problem is that this spec is trying to be more specific...and the more specific something is, the greater the possibility is of inaccuracy. What I had written is _mostly_ true, but it isn't true for _all_ operations. Some operations in particular such as `addAll` actually have to do rather more complex things than delegating operations to the backing Deque. See the implementation for other examples:

https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/ReverseOrderDequeView.java

I don't want to specify the exact behavior of every method. Issues of a similar magnitude occur with the other reversed views. For example, getting the iterator of a reversed SortedSet involves some heavy lifting:

https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java#L206

and I certainly don't want to specify all of that.

So, while in fact the general sense is true that the operations of the reversed view are all implemented via calls to the backing collection, I need to be deliberately vague in certain respects.

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

PR Comment: https://git.openjdk.org/jdk/pull/14504#issuecomment-1593852758


More information about the core-libs-dev mailing list