In Scala, how to test the type of an 'Any' object against a type with type parameter?
I am trying to get a type-safe way of converting the result of parsing a JSON string. I want to check whether a field is Map[String, any] or a plain string. My first attempt is def test(x:Any) = { x match { case m:Map[String,Any] => ... ... } This causes "non-variable type argument String in type pattern Map[String,Any] is unchecked since it is eliminated by erasure" Looking through the document of TypeTag and ClassTag, I could not find a good way to accomplish that. The following code does not cause the warning, but I wonder why it works. type StringMap = Map[String,Any] def test(x:Any) = { x