He was probably caught with the terrible Groovy-Map-Gocha, and he stumbled in the desert of opportunity, as I did all day.
Here's the deal:
When using variable string keys, you cannot access the map in the format of the notation notation (for example, map.abc), something unexpected in Groovy, where everything as a whole is short and wonderful; -)
The workaround is to wrap the variable keys in parens instead of quotes.
def(a,b,c) = ['foo','bar','baz'] Map m = [(a):[(b):[(c):1]]] println m."$a"."$b"."$c" // 1 println m.foo.bar.baz // also 1
Creating such a map will bring great pleasure to sadists around the world:
Map m = ["$a":["$b":["$c":1]]]
Hope this saves another Groovy -ist from temporary insanity ...
source share