Defining a map in Groovy using a variable
Why when I use
['type':x, z:y]
Where
x = 'Car'
z = 'Speed'
y = '1000'
I get a card equal to
[type=Car, z=1000]
but not
[type=Car, Speed=1000]
and how can I overcome it?
+3
user971956
source
to share
2 answers
Surround z
with()
['type':x, (z):y]
According to the docs .
+6
paislee
source
to share
If your Map keys are always strings, the following approach should work as well
['type':x, "$z":y]
0
Dónal
source
to share