RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v4]

ExE Boss duke at openjdk.org
Fri Oct 21 12:13:56 UTC 2022


On Fri, 21 Oct 2022 11:56:57 GMT, Сергей Цыпанов <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/TreeMap.java line 3329:
>> 
>>> 3327:             }
>>> 3328:             else {
>>> 3329:                 return (Comparator<Map.Entry<K, V>> & Serializable) (e1, e2) -> {
>> 
>> I think this cast hints compiler to bootstrap lambda meta factory with extra Serializable marker interface. Meanwhile, Comparator.naturalOrder does not implement Serializable.
>
> From one point this is obviously a change in behaviour, from another the spec of `Spliterator.getComparator()` says nothing about serializability of returned comparator and the actual value is hardly ever going to be serialized.

The only new comparator that is returned here is the one returned by `Map.Entry.comparingByKey()`, which is also `Serializable`.

The only place `Comparator.naturalOrder()` is newly used in this PR are the `final` `package‑private` `getEntry` and `getEntryUsingComparator` methods.

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

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


More information about the core-libs-dev mailing list