ScalaDoc对concurrentMap 这么说:“已弃用(自版本 2.10.0 起)scala.collection.concurrent.Map
改为使用。” 不幸的是,Scala 文档的其余部分尚未更新,仍然引用concurrentMap
.
我尝试混入concurrent.Map
a 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
,还是有更好的方法?