我想在類方法調用期間動態地評估另一個函數的結果。但是,有和Eval的範圍問題。MissingMethodException嘗試在Eval中Groovy
class A {
private String a
public A() {
a = 5
}
public whatIsA() {
return a
}
public func() {
return "\\${whatIsA()}"
}
public test() {
return Eval.me("\"\${func()}\"")
}
}
def a = new A()
a.test()
Exception thrown: groovy.lang.MissingMethodException: No signature of method: Script1.func() is applicable for argument types:() values: {}
groovy.lang.MissingMethodException: No signature of method: Script1.func() is applicable for argument types:() values: {}
at Script1.run(Script1.groovy:1)
at A.test(Script7:17)
at Script7.run(Script7:22)
如何將A類實例的作用域傳遞給Eval腳本?
使用Eval.me而不是eval/evaluate工作得很好,謝謝! – frmdstryr 2014-08-15 18:18:27