【发布时间】:2013-09-10 17:32:10
【问题描述】:
ScalaDoc 对 concurrentMap 的描述如下:“已弃用(自版本 2.10.0 起)请改用 scala.collection.concurrent.Map。”不幸的是,rest of the Scala docs 尚未更新,仍然引用concurrentMap。
我尝试将concurrent.Map 混入HashMap,结果如下:
scala> val mmap = new mutable.HashMap[String, String] with collection.concurrent.Map[String, String]
<console>:16: error: object creation impossible, since:
it has 4 unimplemented members.
/** As seen from anonymous class $anon, the missing signatures are as follows.
* For convenience, these are usable as stub implementations.
*/
def putIfAbsent(k: String,v: String): Option[String] = ???
def remove(k: String,v: String): Boolean = ???
def replace(k: String,v: String): Option[String] = ???
def replace(k: String,oldvalue: String,newvalue: String): Boolean = ???
val mmap = new mutable.HashMap[String, String] with collection.concurrent.Map[String, String]
所以我们看到,除了简单的 mixin,还必须实现一些方法。这是使用concurrent.Map的最佳方式,还是有更好的方式?
【问题讨论】:
标签: scala concurrency hashmap