2 ms·
Wait, it had a concurrenthashmap but no way to "get or add"? Is a concurrent hash map even useful without that? (I suppose you could always write your own with
by alkonaut 10y ago
Wait, it had a concurrenthashmap but no way to "get or add"? Is a concurrent hash map even useful without that? (I suppose you could always write your own with some read/write locking but...wow)
- LgWoodenBadger 10y agoConcurrentMap has always had putIfAbsent(). That requires the thing that you're putting to have been constructed prior to the call. computeIfAbsent() allows you to pass in a lambda (a Function really) which will only be called if necessary, thus avoiding a potentially unnecessary Object creation/etc.