How to create a Map[String,String] from Map[String, Any] in Scala? -
 New in scale - How to     This is true when all values are actually of type   For your misconceptions look:   map [string, string]  to map  are string strings of the map [string, ana]  but I do not know how to enter " any  or otherwise" to type " Type  string  ". As you've mentioned that all your values have a string in the map, you can just  asInstanceOf    
 $ scala Scala version 2.9.2 (OpenZK's 64-bit server VM, Java 1.7.0_55) Welcome to Type them in the expression to evaluate them. Type: Support for more information> Scala & gt; Map (string, any) = map ("foo" -> 5, "bar" -> 7.6, "baz" -> "qux") m: map [string, any] = map (foo - & Gt; 5, times -> 7.6, Falcon -> Cx) Scala & gt; Map (string, any) = map ("FU" -> 5 "," bar "->" 7.6 "," baz "->" qux ") m2: map [string, any ] = Map (FU -> 5, Bar -> 7.6, Falcon -> CX) Scala> M2.asInstanceOf [Map [String, String]] res0: Map [String, String] = Map (FU -> 5, Bar -> 7.6, Falcon -> Qux)    string .   
 scala & gt; Res0 ("foo") res5: string = 5    
 scala> M.asInstanceOf [Map [String, String]] res2: Map [String, String] = Map (FU -> 5, Bar -> 7.6, Falcon -> CX) Scale & gt; Res2 ("foo") can not be molded into java.lang.String at java.lang.ClassCastException: java.lang.Integer & lt; Init & gt; (
 
  
Comments
Post a Comment