How to create a Map[String,String] from Map[String, Any] in Scala? -


New in scale - How to map [string, string] to map , AA] 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

if your assumption is incorrect, then you will get runtime exception as shown below:
  $ 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)   

This is true when all values ​​are actually of type string .

  scala & gt; Res0 ("foo") res5: string = 5   

For your misconceptions look:

  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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -