[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bindings and assignments (was: Re: continuations)
Date: Thu, 14 Aug 2003 08:05:44 -0700
X-Authentication-Warning: orchestra.cs.caltech.edu: mvanier set sender to
firstname.lastname@example.org using -f
From: Michael Vanier <email@example.com>
Cc: firstname.lastname@example.org, email@example.com, firstname.lastname@example.org
Subject: Re: bindings and assignments (was: Re: continuations)
> Date: Thu, 14 Aug 2003 10:45:34 -0400
> From: "David B. Tucker" <email@example.com>
> > 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?
Otherwise you'd have the equivalent of true closures, and if you had that
java would be a *really* powerful and useful language, so they obviously
couldn't do that.
Actually, the prototype implementation *did* allow non-final
variables to be referenced from within inner classes. There was
an outcry from *users*, complaining that they did not want this!
The reason was interesting: in order to support such variables,
it was necessary to heap-allocate them, and (at that time, at least)
the average Java programmer was still pretty skittish about heap
allocation and garbage collection and all that. They disapproved
of the language performing heap allocation "under the table" when
there was no occurrence of the "new" keyword in sight.
Maybe we could lift that restriction in the next few years...