ãã¤ãJavaConvertersã§ãã¾ãããã¨ã¯éããªã
Scalaã¨Javaã®ã³ã¬ã¯ã·ã§ã³ãç¸äºã«å¤æããã«ã¯ scala.collection.JavaConverters
ã便å©ã§ããä¾ãã°Javaã®ã³ã¬ã¯ã·ã§ã³ã« .asScala
ãã¤ããã°ãJavaã®ã³ã¬ã¯ã·ã§ã³ãã©ããããScalaã®ã³ã¬ã¯ã·ã§ã³ãä½ããã¾ãããã ãããã¤ã .asScala
ã§æ¸ãã¨ã¯éãã¾ãããã³ã¬ã¯ã·ã§ã³ã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ã§ã¯ãªããã¼ã¿æ§é ãéè¦ãªå ´åã¯æ³¨æãå¿
è¦ã§ãã
次ã®ã³ã¼ãä¾ã¯ java.util.LinkedHashMap
ã .asScala
ã«å¤æãã¦ã +=
, +
ã®æä½ãè¡ã£ããã®ã§ãã LinkedHashMap
ã¯è¦ç´ ãæ¿å
¥ãããé çªãä¿æããã¯ãã§ããã +=
ã使ã£ãå ´åã¯é çªãä¿æããããã®ã®ã +
ã使ã£ãå ´åã¯é çªãä¿æããã¦ãã¾ããã
val m = new java.util.LinkedHashMap[String, Int]() m.put("field1", 1) m.put("field2", 2) import scala.collection.JavaConverters._ val m2 = m.asScala println(m2) // Map(field1 -> 1, field2 -> 2) m2 += "field3" -> 3 m2 += "field4" -> 4 println(m2) // Map(field1 -> 1, field2 -> 2, field3 -> 3, field4 -> 4)
val m = new java.util.LinkedHashMap[String, Int]() m.put("field1", 1) m.put("field2", 2) import scala.collection.JavaConverters._ val m2 = m.asScala println(m2) // Map(field1 -> 1, field2 -> 2) val m3 = m2 + ("field3" -> 3) + ("field4" -> 4) println(m3) // Map(field1 -> 1, field3 -> 3, field2 -> 2, field4 -> 4)
+=
ã使ã£ãå ´åãæ°ããè¦ç´ ã¯å
ã®LinkedHashMap
ã«æ¿å
¥ããã¾ããä¸æ¹ã +
ã使ã£ãå ´åã¯æ°ã㪠Map
ã®ã¤ã³ã¹ã¿ã³ã¹ãä½ããã¾ãããã®æ°ã㪠Map
ã®ã¤ã³ã¹ã¿ã³ã¹ã¯ JavaConverters
ã§å®ç¾©ãã¦ããã©ããã¼ã¯ã©ã¹ãä½ãã®ã§ãããããã LinkedHashMap
ã§ã¯ãªãé çªãä¿æããªã HashMap
ãªã®ã§ãã
ããã¯å®éã«play-json 2.6.11ã«å
¥ãè¾¼ãã ãã°ã§ããplay-jsonã¯Jsonã®ãã£ã¼ã«ãã Map
ã¨ãã¦ä¿æãã¦ãã¾ããããã® Map
ãScalaã®ãã®ãã java.util.LinkedHashMap
ã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦çæãã¦ã JavaConverters
ã§ã©ããããã¨ããå®è£
ã«å¤ããã¨ãããJsonã®ãã£ã¼ã«ãã®é åºãçãã¨ããç¾è±¡ãèµ·ãã¾ããã
https://github.com/playframework/play-json/issues/236
ã¨ããããã§ãæ°ãã¤ãã¾ãããã