Is it because specific concurrent nature ConcurrentMap ?
SlimerDudeThu 8 Nov 2018
I'm guessing it's because, as the docs say, Fantom's ConcurrentMap is just a wrapper for Java's ConcurrentHashMap so the Fantom getOrAdd() method will undoubtedly just map to Java's putIfAbsent() method as that Java class (from Java 1.5) doesn't understand lambdas or closures.
Note I've created a few Maplike objects over the years and often thought it'd be useful if there was Map mixin so you could easily inherit / override the usual Iterator methods such as each() / find() / findAll() / etc....
brianFri 16 Nov 2018
Correct - its because it routes to the Java method putIfAbsent:
public Object getOrAdd(Object key, Object defVal)
{
Object val = map.putIfAbsent(key, defVal);
return val == null ? defVal : val;
}
Andrey Zakharov Thu 8 Nov 2018
Map:
ConcurrentMap
without lambda
Is it because specific concurrent nature ConcurrentMap ?
SlimerDude Thu 8 Nov 2018
I'm guessing it's because, as the docs say, Fantom's ConcurrentMap is just a wrapper for Java's ConcurrentHashMap so the Fantom
getOrAdd()
method will undoubtedly just map to Java'sputIfAbsent()
method as that Java class (from Java 1.5) doesn't understand lambdas or closures.If you need it, SynchronizedMap from the afConcurrent library is
const
, concurrent, and does have a getOrAdd() method that takes a closure.Note I've created a few
Map
like objects over the years and often thought it'd be useful if there was Map mixin so you could easily inherit / override the usual Iterator methods such aseach() / find() / findAll() / etc...
.brian Fri 16 Nov 2018
Correct - its because it routes to the Java method putIfAbsent: