by meddlepal · 9y ago · 0 comments
if (!map.containsKey(key)) {
V value = compute(key);
V existing = map.putIfAbsent(key, value);
if (existing != null) {
// someone else won the race
}
}Whereas writing a performant concurrent "computeIfAbsent" is extremely non-trivial and if you try to do it yourself, you have a high chance of getting it wrong or slow.
Therefore, CHM "computeIfAbsent" is new and exciting, and Map "computeIfAbsent" is "could care less".