java.util.concurrent.ConcurrentMap's putIfAbsent
docs say the following about the return type:
the previous value associated with the specified key, or null if there was no mapping for the key.
On Scala 2.10.4, I tried to call putIfAbsent(Int, Int)
, i.e. with Scala's Int
type.
scala> import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentHashMap
scala> new ConcurrentHashMap[Int, Int]()
res0: java.util.concurrent.ConcurrentHashMap[Int,Int] = {}
scala> val x: Int = 1
x: Int = 1
Since 1
does not exist in the empty ConcurrentHashMap
, I would expect null
to return from a putIfAbsent(x, x)
call.
scala> res0.putIfAbsent(x, x)
res1: Int = 0
But, 0
gets returned. I'm assuming that null
gets converted to 0
.
What exactly is going on here? It seems odd to me that it's compiling.