[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bindings and assignments (was: Re: continuations)
Date: Thu, 14 Aug 2003 11:31:23 -0400
To: "David B. Tucker" <firstname.lastname@example.org>
From: Scott McKay <email@example.com>
Subject: Re: bindings and assignments (was: Re: continuations)
Cc: David Herman <firstname.lastname@example.org>, Shriram Krishnamurthi
At 10:45 AM -0400 8/14/03, 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?
If you allow the captured variables to be side-effected,
it means that you have to work harder to ensure that the
the captured variable is properly shared between multiple
inner classes that share the lexical environment. That
is, if you only allow final variables to be captured,
you can just copy the value into the "environment" object,
but if they can be written to, you have to introduce a
"cell". To this outside observer, this is a classic
example of implementor laziness -- it would have been
"hard" to do the right thing, so they did the wrong thing,
and everyone who wants inner classes to be useful has
to introduce a bunch of Cell classes manually.
But, as my previous message explains, your assumption
was incorrect. We (or, more specifically, John Rose,
who had previously worked on C* and other languages
using Symbolics Lisp Machines) were far from lazy: he
did the whole shebang. and user feedback made us back off.