The {...} in an each statement is not a normal Java block of code, but a closure. Closures are like classes/methods, so returning from one simply exits out of the closure, not the enclosing method.
Syntax:
def x = [ "a", "b" ] |
Syntax:
String[] x = [ "a", "qrs" ] |
or
String[] x = [ "a", "qrs" ] as String[] |
or
def x = [ "a", "qrs" ] as String[] |
myMap.size or myMap.class return null?In Groovy, maps override the dot operator to behave the same as the index[ ] operator:
myMap["size"]="ONE MILLION!!!"; println myMap.size // outputs 'ONE MILLION!!!' //use the following: println myMap.@size // '1' println myMap.size() // '1' println myMap.getClass() // 'class java.util.HashMap' |
Chances are, you tried to use a variable as a key in a map literal definition.
Remember, keys are interpreted as literal strings:
myMap = [myVar:"one"] assert myMap[ "myVar" ] == "one" |
Try this (note the parentheses around the key):
myMap = [(myVar):"one"] |