[英]Is it possible to get the caller object of a closure in groovy?
是否有可能在Closure
的執行上下文中獲取調用Closure
的Object
引用?
例如:
public class Example {
public Example(){
def a = {return this};
def b = [];
b.metaClass.a = a;
println b.a();
}
}
我希望此執行返回b
而不是Example
。
調用閉包的對象可以作為delegate
引用。 例:
def a = { return delegate }
def b = []
b.metaClass.a = a
assert b.a() == b
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.