Fwd: Map.compute() confusing Javadoc

Paul Sandoz paul.sandoz at oracle.com
Sun Jul 20 20:01:48 UTC 2014


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