Details
-
Sub-task
-
Status: Closed
-
Major
-
Resolution: Information Provided
-
1.5.4
-
None
-
None
-
CentOS 5 n Intel with java 1.6.0_03-b05
Description
The following script executes two closures. One is statically defined in class Test,
the other is returned by Test.makeClosure(). In each case the delegate of the
Closure is set to be an instance of class Delegate, but in one case a call to
method "foo()" appears to resolve to Test.foo(), while in the second it appears
to resolve to Delegate.foo().
I showed this to Dierk at the G2 conference in Reston, and he asked me to post
it as a bug.
=====================================================================
class Test {
def foo()
{ "NOT the delegate" } def makeClosure() {
def closure =
}
static staticClosure =
{ println foo() println delegate.foo() }}
class Delegate {
def foo()
}
Closure dynamicClosure = new Test().makeClosure()
dynamicClosure.setDelegate(new Delegate())
dynamicClosure.call()
Test.staticClosure.setDelegate(new Delegate())
Test.staticClosure.call()
==================================================================
Expected Output:
delegate
delegate
delegate
delegate
Actual Output:
NOT the delegate
delegate
delegate
delegate