我正在尝试从字符串生成闭包。闭包内的代码引用了一个 DSL 函数 build()。我得到的错误暗示 Groovy 正在尝试执行闭包,而不是仅仅声明它。什么是正确的语法?以下是我已经尝试过的一些构造。
sh = new GroovyShell()
cl = sh.evaluate( '{ build("my job") }' }
=> Ambiguous expression could be either a parameterless closure expression or an isolated open code block;
sh = new GroovyShell()
cl = sh.evaluate( 'L: { build("my job") }' }
=> No signature of method: Script1.build() is applicable ...
cl = Eval.me( 'L: { build("my job") }' }
=> No signature of method: Script1.build() is applicable ...
cl = Eval.me( 'L: { com.flow.FlowDelegate.build("my job") }' }
=> No such property: com for class: Script1
我试图遵循的示例来自: 从 Groovy 中的字符串加载闭包代码