Suche…


Syntax

  • $
  • $ {}
  • $ {->}

Basic

def str = 'nice'
assert "Groovy is $str" == 'Groovy is nice'

Gepunkteter Ausdruck

def arg = [phrase: 'interpolated']
assert "This is $arg.phrase" == 'This is interpolated'

Eifriger Ausdruck

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'

Fauler Ausdruck

Wir können träge Interpolation in Strings haben. Dies unterscheidet sich von der normalen Interpolation, da der GString bei jeder Umwandlung in einen String möglicherweise unterschiedliche Werte aufweisen kann.

def str = 'old'
def interpolated = "I am the ${ -> str} value"
assert interpolated == 'I am the old value'
str = 'new'
assert interpolated == 'I am the new value'

Ausdruck

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'


Modified text is an extract of the original Stack Overflow Documentation
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow