Fwd: Map.compute() confusing Javadoc
David Holmes
david.holmes at oracle.com
Sun Jul 20 22:25:53 UTC 2014
See:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018251.html
and related bug report.
David
On 21/07/2014 6:01 AM, Paul Sandoz wrote:
> Begin forwarded message:
>> -------- Пересылаемое сообщение--------
>> 17.07.2014, 19:20, "Roman Leventov" <leventov at ya.ru>:
>>
>> Map.compute() Javadoc has the following paragraph:
>> --------
>> The default implementation is equivalent to performing the following steps for this map, then returning the current value or null if absent:
>>
>> V oldValue = map.get(key);
>> V newValue = remappingFunction.apply(key, oldValue);
>> if (oldValue != null ) {
>> if (newValue != null)
>> map.put(key, newValue);
>> else
>> map.remove(key);
>> } else {
>> if (newValue != null)
>> map.put(key, newValue);
>> else
>> return null;
>> }
>> --------
>>
>> But this code don't correspond neither verbal description of the behaviour nor the actual default implementation in java.util.Map. If the oldValue is null and newValue is null, map should still remove the key, not to just `return null;`
>>
>
More information about the core-libs-dev
mailing list