Trois propriétés des fermetures, propriétaire, et délégué . En général, délégué est défini sur propriétaire.
def testClosure(closure) {
closure()
}
testClosure() {
println "this is " + this + ", super:" + this.getClass().superclass.name
println "owner is " + owner + ", super:" + owner.getClass().superclass.name
println "delegate is " + delegate + ", super:" + delegate.getClass().superclass.name
testClosure() {
println "this is " + this + ", super:" + this.getClass().superclass.name
println "owner is " + owner + ", super:" + owner.getClass().superclass.name
println "delegate is " + delegate + ", super:" + delegate.getClass().superclass.name
}
}
empreintes
this is ConsoleScript0@11d20d3, super:groovy.lang.Script
owner is ConsoleScript0@11d20d3, super:groovy.lang.Script
delegate is ConsoleScript0@11d20d3, super:groovy.lang.Script
this is ConsoleScript0@11d20d3, super:groovy.lang.Script
owner is ConsoleScript0$_run_closure1@caea19, super:groovy.lang.Closure
delegate is ConsoleScript0$_run_closure1@caea19, super:groovy.lang.Closure