RFR: 8362958: Unnecessary copying / sorting in Streams using Comparator.naturalOrder() [v8]
Patrick Strawderman
duke at openjdk.org
Sat Nov 15 02:08:01 UTC 2025
On Sat, 15 Nov 2025 00:03:40 GMT, Chen Liang <liach at openjdk.org> wrote:
> I don't know about the particular case about TreeSet, but I think with the advent of Comparator.naturalOrder in Java 8, people are much more likely to use it instead of null to represent the natural order, especially for Comparator-returning methods or Comparator fields. Offering such a conversion within the implementation, in my opinion, is better than checking and converting at every single use site that has a Comparator.
I agree with that, I think it seems better to *not* use null to signal natural order. But even if we did that here, the stream classes like `SortedOps` still need to handle null or `Comparator.naturalOrder()`, since the null signaling natural order is part of the contract of SortedSet, Spliterator, etc.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28226#issuecomment-3535399552
More information about the core-libs-dev
mailing list