From the spec: “If the map previously contained a mapping for the key, the old value is replaced by the specified value.” I’m wondering about the situation where value.equals(the old value) but value != the old value. My reading of the spec is that the old value must still be replaced. Is that right?
Share
If a new key matches an existing key, the mapped value will be replaced regardless of it’s value, e.g. even if
oldValue.equals(newValue)istrue.I don’t think that we need to look at source, or rely on test code: this is explicit from the documentation for
Map.put, where we find: