How to implement Map with default operation in Scala -


class defaultlistmap[a, b <: list[b]] extends hashmap[a, b] {     override def default(key: a) = list[b]()    } 

i wan't create map a -> list[b]. in case long -> list[string] when key map doesn't have value create empty list instead of exception being thrown. tried different combinations don't know how make code above pass compiler.

thanks in advance.

why not use withdefaultvalue(value)?

scala> val m = map[int, list[string]]().withdefaultvalue(list()) m: scala.collection.immutable.map[int,list[string]] = map()  scala> m(123) res1: list[string] = list() 

Comments

Popular posts from this blog

c# - Getting control value when switching a view as part of a multiview -

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -