Suggestion for a more sensible implementation of EMPTY_MAP
abraham.marin.perez at gmail.com
Fri Jun 7 13:21:34 UTC 2019
Cross posting from core-libs-dev as suggested.
I'm a first timer here, I just joined the group as suggested by Martijn
Verburg to make a suggestion for a slight change in the implementation of
If I understand correctly, this class represents an immutable empty map. As
a result, operations like put or remove have been implemented to throw
UnsupportedOperationException; this makes sense to me. However, this is
also the implementation for computeIfPresent, which I believe may be too
disruptive: the definition of this method says “If the value for the
specified key is present and non-null, attempts to compute a new mapping
given the key and its current mapped value.“; for an empty map, this could
be a safe no-op, instead of an exception.
I was wondering if this is something that would make sense to there people
too (feedback appreciated). If so, I'm happy to provide a patch for the
change (we just need to leave an empty body for the method).
Please let me know what you think,
More information about the adoption-discuss