Idea: "Frozen" inner function
Frank Benoit (keinfarbton)
benoit at tionex.removethispart.de
Sun Nov 26 02:42:35 PST 2006
This is the case for Java also. If you define a anonymous class in a
method it can access the local variable and arguments of the surrounding
method. The compiler forces them to be final.
This is exactly like finding all references to the surrounding method,
and make a copy of all accessed vars.
e.g.
class MyClass{
int fld_i;
double fld_d;
void f( final int i, double d ){
ListenerType l = new ListenerType(){
void event( ){
fld_i = i; // OK
fld_i++; // OK
i++; // Error, i is final
fld_d = d; // Error, can only access final variables
}
}
}
}
More information about the Digitalmars-d
mailing list