Watch This Video
------------------------------------------------------------------------------------------------------------------class ScopeDemo{
def outerClosure ={
println this.class.name
println owner.class.name
println delegate.class.name
def innerClosure={
println this.class.name
println owner.class.name
println delegate.class.name
}
innerClosure()
}
}
def demo=new ScopeDemo()
//other Example
def writer={
append 'Dan'
append 'lives in USA'
}
def append(String s){
println "append() called with argument of $s"
}
StringBuffer sb= new StringBuffer()
writer.resolveStrategy=Closure.DELEGATE_FIRST
writer.delegate=sb
writer()
No comments:
Post a Comment
Note: only a member of this blog may post a comment.