How to use a variable for the key part of a map

前端 未结 2 1403
小鲜肉
小鲜肉 2021-01-30 10:03

Let\'s say I have

def A = \"abc\"
def X = \"xyz\"

how do I create a Map where, instead of

def map = [A:1, X:2]
         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 10:44

    Use this:

    def map = [(A):1, (X):2]
    

    For the value-part it's even easier, since there is no automagic "convert text to string" happening:

    def map = [keyA:A, keyX:X]
    

提交回复
热议问题