我正在尝试将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 MultiMapof types A&B是 a Mapof 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
似乎泛型又让我绊倒了。