雙引號字串(插值)
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'