groovy Strings and GString literals Double quoted string (interpolation)


Example

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

The parameter is by default resolved eagerly, this means this applies:

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

In order to load the parameter lazily every time the string is used, this can be done:

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