In addition to Joachim's answer , if you want to add entries to an existing map, and the keys are variables, use:
def map = [:] def A = 'abc' map[A] = 2
If you use:
map.A = 2
It is assumed that you want to use the letter string 'A' as the key (although there is a variable called A. in the scope
Update
As @tim_yates noted in the comment, the key variable will also be allowed if you use:
map."$A" = 2
although I personally prefer to use the syntax [A] , as refactoring tools may skip the link "$A" if the variable is renamed
DΓ³nal Oct 13 2018-11-11T13
source share