RFR: 6323374: (coll) Optimize Collections.unmodifiable* and synchronized* [v5]
Ian Graves
igraves at openjdk.java.net
Thu Mar 4 02:04:44 UTC 2021
On Thu, 4 Mar 2021 02:01:02 GMT, Ian Graves <igraves at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/Collections.java line 1168:
>>
>>> 1166: */
>>> 1167: public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) {
>>> 1168: if (s.getClass() == UnmodifiableSortedSet.class) {
>>
>> Should a check like this also included "|| == UnmodifiableNavigableSet.class" or was there an explicit decision that the cost/benefit is not worthwhile, unlike in the case of unmodifiableList below?
>
> This is a good point. The case of unmodifiableList is such because the method can return two different classes depending the nature of the argument. I feel as though if we made this change here, we should consider doing the same check for vanilla unmodifiableSet to ensure it, too, doesn't wrap its subclasses. I'm amenable to this.
To the second part of the question, there was no explicit cost/benefit analysis RE List or this case.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2596
More information about the core-libs-dev
mailing list