ConcurrentHashMap/ConcurrentMap/Map.compute (original) (raw)

Doug Lea dl at cs.oswego.edu
Fri Dec 14 08:56:56 PST 2012


On 12/14/12 11:46, Brian Goetz wrote:

But, I am not quite following your argument. Why does it fail if you replace "map.get(key) == null" with "!map.containsKey(key)"? For non-null-accepting maps they are equivalent.

Consider the unlikely prospect of a null-accepting ConcurrentMap. And let's pick on computeIfPresent. If I try to trigger function on containsKey(key), then by the time I get(key) for function arg, it could have been removed (and rechecking doesn't help). And if I do the opposite, trigger on (v = get(key)) != null || containsKey, then v could be wrong. Either way loses.

-Doug



More information about the lambda-libs-spec-experts mailing list