<p>I'm trying to mixin the <code>MultiMap</code> trait with a <code>HashMap</code> like so:</p>

<pre><code>val children:MultiMap[Integer, TreeNode] = 
    new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode]
</code></pre>

<p>The definition for the <code>MultiMap</code> trait is:</p>

<pre><code>trait MultiMap[A, B] extends Map[A, Set[B]]
</code></pre>

<p>Meaning that a <code>MultiMap</code> of types <code>A</code> &amp; <code>B</code> is a <code>Map</code> of types <code>A</code> &amp; <code>Set[B]</code>, or so it seems to me. However, the compiler complains:</p>

<pre><code>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  
</code></pre>

<p>It seems that generics are tripping me up again.</p>

[{'answer_id': 50420, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': 6, 'selected': True, 'text': '<p>I had to import <code>scala.collection.mutable.Set</code>. It seems the compiler thought the Set in <code>HashMap[Integer, Set[TreeNode]]</code> was <code>scala.collection.Set</code>. The Set in the MultiMap def is <code>scala.collection.</code><strong><code>mutable</code></strong><code>.Set</code>. </p>\n'}, {'answer_id': 64396, 'author': 'Calum', 'author_id': 8434, 'author_profile': 'https://Stackoverflow.com/users/8434', 'pm_score': 4, 'selected': False, 'text': "<p>That can be annoying, the name overloading in Scala's collections is one of its big weaknesses.</p>\n\n<p>For what it's worth, if you had <code>scala.collection._</code> imported, you could probably have written your <code>HashMap</code> type as:</p>\n\n<pre><code>new HashMap[ Integer, mutable.Set[ TreeNode ] ]\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/50373', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4893/']