user971956
user971956

Reputation: 3208

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 map equal to

[type=Car, z=1000]

and not

[type=Car, Speed=1000]

and how can I overcome it?

Upvotes: 3

Views: 958

Answers (2)

Dónal
Dónal

Reputation: 187379

If the keys of your Map are always strings, the following approach should also work

['type':x, "$z":y]

Upvotes: 0

calebds
calebds

Reputation: 26228

Surround the z with ()

['type':x, (z):y]

As per docs.

Upvotes: 6

Related Questions