Ba bất động sản đóng cửa , là này, chủ sở hữu, và ủy, Trong đại biểu nói chung được thiết lập để chủ sở hữu
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
}
}
in
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
Trang thứ hai của google có tài liệu về nó: http://groovy.codehaus.org/Closures#Closures-this%2Cowner%2Canddelegate. Hi vọng điêu nay co ich. – Esailija
http://mrhaki.blogspot.com/2009/11/groovy-goodness-setting-closures.html –