How about just calling .toMap on it?
import collection.JavaConversions._ val x = java.util.Collections.unmodifiableMap[Int,Int](new java.util.HashMap[Int,Int]()) val y: Map[Int,Int] = x.toMap //y: Map[Int,Int] = Map()
Without calling toMap , JavaConversions allows you to implicitly convert to a Scala mutable map:
scala> val z: collection.mutable.Map[Int,Int] = x z: scala.collection.mutable.Map[Int,Int] = Map()
Presumably this is because the Java Map is mutable, so it should only be represented in Scala as mutable.Map , unless you explicitly convert it to immutable.Map .
Note that when you just say Map in Scala, you are really talking about collection.immutable.Map , since Predef aliases Map as follows:
scala> Map() res0: scala.collection.immutable.Map[Nothing,Nothing] = Map()
So, when you say request.getParameterMap.asInstanceOf[Map[String, Array[String]]] , you really ask Scala to implicitly convert Java Map to Scala collection.immutable.Map , which it does not want to do since Java Map is mutable.
source share