Nice to @Share?
Neal Gafter
neal at gafter.com
Tue Feb 23 08:03:38 PST 2010
On Tue, Feb 23, 2010 at 3:17 AM, Alex Buckley <Alex.Buckley at sun.com> wrote:
> Neal Gafter wrote:
>> The definition of "local variable" in (§4.12.3) is ...
>
>> The only part of that requiring rewording in the presence of lambdas
>> that can access local variables from the enclosing scope is the last
>> sentence. The rewording is required whether or not such variables are
>> final. In fact, that last sentence appears to conflict with the fact
>> that final variables can be accessed in an anonymous inner class after
>> the scope containing the variable has completed.
>
> Consider also JLS3 17.4.1: "Local variables ... are never shared between
> threads and are unaffected by the memory model." A variable hoisted on
> to the heap is not a local variable, even if its declaration form looks
> similar to a local variable declaration statement. For example, you
> could morally have a volatile shared variable, whereas you cannot have a
> volatile local variable.
Right... that sentence would have to be removed, and "volatile"
allowed on local variables.
More information about the lambda-dev
mailing list