1
我從GroovyConsole得到這個程序。我在這裏複製以方便參考,這個Groovy代碼是做什麼的?
def aClosure = { String name ->
println "hi "+name
sayHello()
println wro4j
}
aClosure.delegate = new MyClass()
aClosure.resolveStrategy = Closure.DELEGATE_FIRST
def result = aClosure("Toto")
class MyClass{
String wro4j = "Wro4J rocks !!!"
void sayHello(){
println "Hello"
}
}
我找不出上述代碼的作用。
什麼是resolveStrategy
和delegate
相對於aClousre
?