Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
a = 0
b = 1
x =
{ System.out.println('on entry to closure a = ' + a) System.out.println('on entry to closure b = ' + b) a++ System.out.println('on exit from closure a = ' + a) System.out.println('on exit from closure b = ' + b) }x.setDelegate(this)
System.out.println('before first call a = ' + a)
System.out.println('before first call b = ' + b)
x.call()
System.out.println('after first call a = ' + a)
System.out.println('after first call b = ' + b)
System.out.println()
a *= 2
b *= 2
System.out.println('before second call a = ' + a)
System.out.println('before second call b = ' + b)
x.call()
System.out.println('after second call a = ' + a)
System.out.println('after second call b = ' + b)
This produces:
before first call b = 1
on entry to closure a = 0
on entry to closure b = 1
on exit from closure a = 1
on exit from closure b = 1
after first call a = 1
after first call b = 1
before second call a = 2
before second call b = 2
on entry to closure a = 2
on entry to closure b = 1
on exit from closure a = 3
on exit from closure b = 1
after second call a = 3
after second call b = 2
You will see that b is still 1 in the second call to the closure.