RFR 8078645: removeIf(filter) in ConcurrentHashMap removes entries for which filter is false

Doug Lea dl at cs.oswego.edu
Tue May 5 10:42:11 UTC 2015

On 05/05/2015 05:12 AM, Paul Sandoz wrote:
> On May 5, 2015, at 7:54 AM, Martin Buchholz <martinrb at google.com> wrote:
>> One query in ConcurrentSkipListMap, we have:
>> 2500             // else use iterator
>> 2501             @SuppressWarnings("unchecked") Iterator<Map.Entry<Object,E>> it =
>> 2502                     ((SubMap<Object,E>)m).entryIterator();
>> and then
>> 2578             // else use iterator
>> 2579             Iterator<Map.Entry<K1,V1>> it = ((SubMap<K1,V1>)m).entryIterator();
>> why does only the former require the "unchecked" warning suppression?
>> Good question.
> Yes, for values the key type parameter is "thrown" away and reconstituting as Object is not type safe.

It was originally done this way because keeping the "K" parameter hit
a generics type parameter inference limitation. Similarly for some
constructions in TreeMap. But I think jdk8 (not just 9) allow this to
be done with explicit type parameters, so now is as good a time to
update this as any, combining both Martin's and Paul's changes.
Someone might also want to look at TreeMap.


More information about the core-libs-dev mailing list