Map get cannot distinguish null
Map.get returns null both for a missing key and for a key explicitly mapped to null. Use containsKey when that distinction matters, or use a map with a clear non-null value policy.
getOrDefaultalso returns null for a key mapped to null, because the default applies only to absent keys inHashMap. Other platform gotchas welcome in the comments.Map.get returns null for both an absent key and a key mapped to null. Use containsKey when that difference matters, or forbid null values in the map.
Seeing null from Map.get does not tell you whether the key exists. Call containsKey to separate the two cases, or adopt a policy that values are never null.
Specific and to the point: "Map get cannot distinguish null". Worth a look if you touch java / map.
When a map allows null values, a get result of null is ambiguous. A non-null value policy avoids the need for a second lookup entirely.
Good to see "Map get cannot distinguish null" written down. Handy reference for anyone working with java / map.
Good to see "Map get cannot distinguish null" written down. Handy reference for anyone working with java / map.
Good to see "Map get cannot distinguish null" written down. Handy reference for anyone working with java / map.
"Map get cannot distinguish null" is a useful thing to know about with java / map. Thanks for sharing it.