简体   繁体   中英

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?

Surround the z with ()

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

As per docs .

如果Map的键始终是字符串,则以下方法也应该有效

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM