Groovy:插入到文本中的字符串列表丢失了撇号

Groovy: List of Strings interpolated into a text loses apostrophes

我想创建一个文本,在其中插入字符串列表 ["aa","bb"]。

def texts = ["aa" , "bb"]
def out = "my list: $texts"
println out

我希望输出为:

my list: ["aa","bb"]

但我得到的输出是:

my list: [aa, bb]

我该如何解决这个问题?

texts.toString()的结果不包含引号。所以你必须自己创建输出:

def out = "my list: ${texts.collect{'"' + it + '"'}}"