Let's say I evaluate the following:
key = "actualKey"
map = [key:"value"]
print map
The result will be: {key=value}. What I would like to get is {actualKey=value}
Is this a bug or an intended feature? Basically the key of a map is always interpreted as a string - even if it matches an actual string variable in the scope.
I can use the following workaround, but I feel it's a bit ugly. Are there any better alternatives available?
key = "actualKey"
map = ["$key":"value"]
print map
By default, keys are strings, so when writing map = [key:"value"], it's equivalent to map = ["key":"value"]
If you actually want to use the value of a variable as a key, you have to put the key between parentheses: map = [(key):"value"]