title: Scala: Using HashMap with a default value
body: <p>I have a mutable HashMap and would like to use it like a default-dictionary. The obvious method appears to be to use getOrElse and provide the default value each time as a second value. However this seems a little inelegant in my use case since the default value doesn't change.</p>
  
  <pre><code>var x = HashMap(1 -&gt; "b", 2 -&gt; "a", 3 -&gt; "c")
  
  println(x.getOrElse(4, "_")
  println(x.getOrElse(5, "_"))
  // And so on...
  println(x.getOrElse(10, "_"))
  </code></pre>
  
  <p>Is there any way to create a HashMap (or similar class) such that attempting to access undefined keys returns a default value set on the creation of the HashMap? I notice that HashMap.default is just set to throw an exception but I wonder if this can be changed...</p>