RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v2]
Сергей Цыпанов
duke at openjdk.org
Fri Oct 14 08:57:08 UTC 2022
On Thu, 13 Oct 2022 21:46:15 GMT, ExE Boss <duke at openjdk.org> wrote:
>> Nope, there'd be a compilation error
>
> It'll work fine if an unchecked cast is used:
> Suggestion:
>
> @SuppressWarnings("unchecked")
> Comparator<Map.Entry<K, V>> entryComparator = treeComparator == null ?
> (Comparator) Map.Entry.comparingByKey()
> Map.Entry.comparingByKey(treeComparator);
> return entryComparator;
>
>
> This also ensures that when `treeComparator` is `null`, this method keeps returning a constant lambda.
This one looks fine, accepted.
-------------
PR: https://git.openjdk.org/jdk/pull/9901
More information about the core-libs-dev
mailing list