Map.merge Javadoc is confusing

Louis Wasserman lowasser at
Thu Nov 21 18:17:57 UTC 2013

The Javadoc for
that its default implementation is equivalent to:

V oldValue = map.get(key);
 V newValue = (oldValue == null) ? value :
              remappingFunction.apply(oldValue, value);
 if (newValue == null)
 else if (oldValue == null)
     map.put(key, newValue);

I'm somewhat confused by the second branch of this if statement, which is
reached if newValue is nonnull and oldValue is null.  Does this really
*remove* the entry for that key?  I would have expected there to be only
two branches: either remove the entry if newValue is null, or put newValue
if it's nonnull.

Louis Wasserman

More information about the core-libs-dev mailing list