The test call uses a third-party function that returns Option[Any] . I know if this function returns a Map , it is a Map[String, Any] . In this case, I want to check the individual elements of the map.
theFunction(...) match { case Some(m: Map[String, Any]) => m("some key") match { case some_condition => ... (my check) } case _ => fail("Invalid type") }
But the compiler warns that case Some(m: Map[String, Any]) not installed. When I use Map[_,_] instead, the compiler is taken at the point where I check m("some key") .
How to suppress this warning or better: how to do it right? The only approach I can think of is something like
theFunction(...) match { case Some(m: Map[_,_]) => val m1: Map[String, Any] = m.toSeq.map(t => t._1.asInstanceOf[String] -> t._2).toMap m1("some key") match { case some_condition => ... (my check) } }
but in my eyes it looks ugly and introduces an unnecessary map conversion to Seq and vice versa.
source share