This is my example code for this question:
class Person {
String fullName
}
def myClosure = {
fullName = "Chakroun Anas"
}
Person person = new Person()
myClosure.delegate = person
myClosure()
println(person.fullName)
This is the output :
null
So is it possible to access the delegate object properties from the closure ? if so then how ?
Thanks in advance.
Consider this (using this page as a reference):
class Person {
String fullName
}
def myClosure = {
fullName = "Chakroun Anas"
}
Person person = new Person()
myClosure.resolveStrategy = Closure.DELEGATE_FIRST
myClosure.delegate = person
myClosure()
println(person.fullName)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.