dave08
11/07/2018, 3:05 PMpublic inline fun <K, V> ConcurrentMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
// Do not use computeIfAbsent on JVM8 as it would change locking behavior
return this.get(key)
?: defaultValue().let { default -> this.putIfAbsent(key, default) ?: default }
}
The problem is that if defaultValue
returns null
, putIfAbsent
will crash with an NPE... is there a way to ensure that it should not be able to receive nulls?