I'm trying to mixin the MultiMap
trait with a HashMap
like so:
val children:MultiMap[Integer, TreeNode] =
new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode]
The definition for the MultiMap
trait is:
trait MultiMap[A, B] extends Map[A, Set[B]]
Meaning that a MultiMap
of types A
& B
is a Map
of types A
& Set[B]
, or so it seems to me. However, the compiler complains:
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
It seems that generics are tripping me up again.