Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Scala immutable HashMap methods return a Map?

I am having problems using the update method of scala.collection.immutable.HashMap.I don't see the reason it returns a Map instead of a HashMap. How do I get a new HashMap with a new key-value pair added?

like image 210
pau.estalella Avatar asked Dec 06 '22 03:12

pau.estalella


1 Answers

That's the expected behavior. HashMap is most useful as a specific implementation of Map involving using a hash table for lookups.

Usually, you'd say var values: Map[String, Any] = new HashMap, and then sit back and use it as if it's a plain ol' immutable Map.

Do you have a reason for your code to know that it's a HashMap after you've new'd it as above?

like image 191
sblom Avatar answered Dec 21 '22 17:12

sblom