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'