我正在尝试将MultiMap
特征与HashMap
这样的混合:
val children:MultiMap[Integer, TreeNode] =
new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode]
特征的定义MultiMap
是:
trait MultiMap[A, B] extends Map[A, Set[B]]
这意味着 a MultiMap
of types A
&B
是 a Map
of types A
& Set[B]
,或者在我看来是这样。但是,编译器抱怨:
C:\...\TestTreeDataModel.scala:87: error: illegal inheritance; template $anon inherits different type instances of trait Map: scala.collection.mutable.Map[Integer,scala.collection.mutable.Set[package.TreeNode]] and scala.collection.mutable.Map[Integer,Set[package.TreeNode]]
new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode]
^ one error found
似乎泛型又让我绊倒了。