Tutorial by Examples

def str = 'nice' assert "Groovy is $str" == 'Groovy is nice'
def arg = [phrase: 'interpolated'] assert "This is $arg.phrase" == 'This is interpolated'
def str = 'old' def interpolated = "I am the ${str} value" assert interpolated == 'I am the old value' str = 'new' assert interpolated == 'I am the old value'
We can have lazy interpolation in Strings. This is different than normal interpolation as the GString can potentially have different values, depending on the closure, whenever it is converted into a String. def str = 'old' def interpolated = "I am the ${ -> str} value" assert interpo...
def str = 'dsl' def interpolated = "Groovy ${str.length() + 1} easy ${str.toUpperCase()}" assert interpolated == 'Groovy 4 easy DSL' str = 'Domain specific language' assert interpolated == 'Groovy 4 easy DSL'

Page 1 of 1