我在Scala中使用了ConcurrentHashMap
,我想使用computeIfAbsent()
方法,但無法弄清楚第二個參數的語法。有人可以告訴我什麼是正確的語法?如何在Scala中使用ConcurrentHashMap computeIfAbsent()
當運行下面的代碼
val data = new ConcurrentHashMap[String, LongAdder]
data.computeIfAbsent("bob", k: String => new LongAdder()).increment()
我收到以下錯誤
Type mismatch, expected: Function[_ >: String, _ <: LongAdder], actual: (String) => Any
請多關照
弗朗西斯