[英]How to access delegate object properties in groovy?
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. 提前致谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.