import scala.collection._
import scala.collection.JavaConversions._
val myMap: mutable.Map[K,V] = ???
val unmodifiable: mutable.Map[K,V] =
java.util.Collections.unmodifiableMap[K,V](myMap)
val newMap = unmodifiable.asInstanceOf[scala.collection.Map[K,V]]
You can apply newMapto mutable.Map, but changes will throw UnsupportedOperationException.
In my case, the cards can be small enough to toMapbe faster and use less memory.
source
share