双引号字符串(插值)

def param = 'string'
def str = "Double quoted ${param}"
assert str instanceof GString
assert str == 'Double quoted string'

默认情况下,该参数是急切解决的,这意味着这适用:

def param = 'string'
def str = "Double quoted ${param}"
param = 'another string'
assert str == 'Double quoted string'

为了在每次使用字符串时懒惰地加载参数,可以这样做:

def param = 'string'
def str = "Double quoted ${ -> param}"
assert str == 'Double quoted string'
param = 'lazy load'
assert str == 'Double quoted lazy load'