[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: bindings and assignments (was: Re: continuations)



David B. Tucker wrote:
> > I imagine, though I don't have statistical evidence, that the
> > requirement of declaring local variables to be final in order to
> > reference them within anonymous inner classes (closures) is almost
> > entirely unknown and unused in practice.
> 
> Out of curiosity, does anyone know why Java only allows final 
> variables to be referenced from within anonymous classes?

Because anonymous classes aren't closures. The anonymous class instance
actually gets a copy of the local, so you can't modify the local, to
make this clear (that you understand this) it has to be final.

Regards,
Jeroen