0

Can anyone explain what's going on in this dense code:

val m = new mutable.HashMap[Int, mutable.Set[String]] with mutable.MultiMap[Int, String]
lolski
  • 16,231
  • 7
  • 34
  • 49

1 Answers1

1

As much as I know,

new mutable.HashMap[Int, mutable.Set[String]]      

creates a mutable HashMap having key as Int and values as mutable Set of Strings

with mutable.MultiMap[Int, String]

This suggests that mutable.HashMap is enforced to mix-in mutable.MultiMap. The following can be the definition of HashMap

class HashMap {
   self: mutable.MultiMap => 
}

This is called as self annotation. It basically says that HashMap is not a multimap but its instances are promised to be so, therefore you can code HashMap as if it was a multimap

mohit
  • 4,968
  • 1
  • 22
  • 39