Tres propiedad de los cierres , son esto, propietario, y delegar, En delegado general se expone al propietario
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
}
}
impresiones
this is [email protected], super:groovy.lang.Script
owner is [email protected], super:groovy.lang.Script
delegate is [email protected], super:groovy.lang.Script
this is [email protected], super:groovy.lang.Script
owner is [email protected], super:groovy.lang.Closure
delegate is [email protected], super:groovy.lang.Closure
La segunda página de Google sin embargo tiene documentación para ello: http://groovy.codehaus.org/Closures#Closures-this%2Cowner%2Canddelegate. Espero que esto ayude. – Esailija
http://mrhaki.blogspot.com/2009/11/groovy-goodness-setting-closures.html –