I have a scala code snippet given below:
// country code to nameToPlaces traversable
val input : Traversable[(Int, java.util.Map[String, java.util.Set[String]])] ...
val nameToPlacesMap : Map[String, Set[String]] = input.toMap.
values.
map (x => x.toSeq). // throws a class cast exception
reduce((x,y) => x ++ y).
groupBy(_._1).
mapValues(_.map(_._2).
reduce((x,y)=>x.toSet ++ y.toSet))
nameToPlacesMap
is expected to collate all nameToPlaces from all countries.
However, while running this code, i am getting a classcastexception
java.util.HashMap cannot be cast to scala.collection.immutable.Map
I have tried adding asScala
but of no use. I am also importing import scala.collection.JavaConverters._
Any help will be appreciated.
NOTE: I don't see this question as a duplicate of a generic classcast exception as noted below: Please revise your judgement.