I was writing code and I noticed some odd behavior in Groovy when I am dealing with XML and Maps. I thought about it and can\'t figure out why is it happening and should it
Here is a demonstration of this quirk of double quoted strings in Groovy:
Double quoted strings are plain
java.lang.Stringif there’s no interpolated expression, but aregroovy.lang.GStringinstances if interpolation is present.
groovy:000> m = [:]
===> {}
groovy:000> tmp = "wat"
===> wat
groovy:000> key = "${tmp}"
===> wat
groovy:000> m << ["${key}": "hi"]
===> {wat=hi}
groovy:000> m["${key}"] = "hi"
===> hi
groovy:000> m
===> {wat=hi, wat=hi}
groovy:000> m["wat"] = "fuuuuuu!"
===> fuuuuuu!
groovy:000> m
===> {wat=hi, wat=fuuuuuu!}
groovy:000> m.keySet().each { println it.class }
class org.codehaus.groovy.runtime.GStringImpl
class java.lang.String
Enjoy ;)