While fields marked with @Field get initialized properly when used inside
closures, when used in regular classes, their initialization does not happen
properly (it should be correctly moved to the constructors).
The snippet below demonstrates the difference between the 2 cases:
--------------------------------------------------
@Typed package test
def foo() {
@Field mf = 5
mf++
println mf
}
println "@Field usage inside closure"
(1..2).each{
@Field cf = 5
cf++
println cf
}
println "@Field usage inside method"
(1..2).each{
foo()
}
--------------------------------------------------
In both the cases, the output is expected to be 6, 7 - but for the method case,
it incorrectly comes as 1, 2 because the field's initial value of 5 is lost.
Original issue reported on code.google.com by roshanda...@gmail.com on 16 Oct 2010 at 4:28
Original issue reported on code.google.com by
roshanda...@gmail.com
on 16 Oct 2010 at 4:28