Need Groovy syntax help for generating a Closure from a String

后端 未结 4 722
醉梦人生
醉梦人生 2020-12-21 18:03

I\'m trying to generate a closure from a string. The code inside the closure references a DSL function build(). The errors I\'m getting imply that Groovy is trying to exec

4条回答
  •  独厮守ぢ
    2020-12-21 18:25

    What about returning the closure from the script?

    Eval.me("return { build('my job') } ")
    

    What do you intend using that L:? Returning a map? If is that so, you can use square brackets:

    groovy:000> a = Eval.me("[L: { build('test for') }]")
    ===> {L=Script1$_run_closure1@958d49}
    groovy:000> a.L
    ===> Script1$_run_closure1@958d49
    

提交回复
热议问题