Why Map withDefaultValue returns Option = None
dictionary, scala
Solution
You want to use `apply` instead of `get`.
scala> m("ss")
res0: Int = 0
`apply` returns the value type of the `Map`, and will using the default value. `get` returns an `Option` based on the existence of the specified key.
Problem
I'm using Scala 2.10.4 and I cannot figure out why I cannot get the default value for non existent keys. What I get instead is `Option[Int]` with value of `None`. ``` val m = Map[String, Int]().withDefaultValue(0) //> m : scala.collection.immutable.Map[String,Int] = Map() m.get("ss") //> res0: Option[Int] = None ``` I expected res0 to be `0`. Why it is not? How can I obtain the expected behaviour?