11 ms·
Neither is 'merely syntactic sugar', take a look at their respective implementations. It's hardly surprising that a method on a class named 'ConcurrentHashMap'
by pvg 10y ago
Neither is 'merely syntactic sugar', take a look at their respective implementations. It's hardly surprising that a method on a class named 'ConcurrentHashMap' in 'java.util.concurrent' provides certain concurrency-related guarantees. It's the point of the whole thing and is written on the tin.
- astral303 10y agoDefault Java 8 Map implementation is merely: "get X. if X absent, compute for X, put X." These lines of code have been written over and over again for anyone using a Map in Java, no doubt. It is entirely trivial and almost impossible to get wrong writing it out on your own. 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".
- pvg 10y agoDefault Java 8 Map implementation is merely Worth noting that's not actually the HashMap implementation.