You do not need @Field
transformation in case where you call anonymous class and refer the field variable.
Reason:
When a strictly typed variable in a script is defined as @Field
then that variable (at compile time [AST transformed]) is treated as private inside that script. Hence property missing.
In order to realize the difference, just visualize the script in AST browser from Groovy console and go through the "Semantic Analysis" phase under both cases (without and with @Field), you would notice the variable is local to run()
for the main script as compared to defined globally otherwise respectively.
Corollary:
On the other hand, @Field
transformation is useful when strictly typed variables are to be used in a method inside the same script because without @Field
the field will be declared as a local variable in the run()
method of the script, hence not visible to other methods.
Excerpts from AST browser for details.