Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以获得在执行上下文Object中调用 a的引用?ClosureClosure
Object
Closure
例如:
public class Example { public Example(){ def a = {return this}; def b = []; b.metaClass.a = a; println b.a(); } }
我希望此执行返回b而不是Example.
b
Example
调用闭包的对象可以引用为delegate. 例子:
delegate
def a = { return delegate } def b = [] b.metaClass.a = a assert b.a() == b