0
訪問Groovy中另一個腳本中定義的閉包的正確和最簡單的方法是什麼?這可能不是最好的設計,但我有在其他腳本中定義的呼叫閉包
SomeScript.groovy定義的封閉
bindingC = {
...
}
def localC = {
...
}
OtherScript.groovy
SomeScript s = new SomeScript()
s.bindingC(...);
s.localC(...);
注:SomeScript.groovy是程序邏輯和OtherScript。 groovy是單元測試邏輯。它們都在同一個包中,我可以在SomeScript中訪問方法。
本地關閉無法訪問權限?因爲它就像一個方法的局部變量。 – xst 2013-04-23 19:17:11
這是正確的.. – Will 2013-04-25 13:11:49
@xst,也有groovy轉換'@ Field',它可以改變腳本變量的範圍:http://groovy.codehaus.org/gapi/groovy/transform/Field.html – Will 2013-05-04 11:34:47