Nice to @Share?
Alex.Buckley at Sun.COM
Tue Feb 23 03:17:33 PST 2010
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.
More information about the lambda-dev