capturing (or not) mutable local variables

Neal Gafter neal at gafter.com
Sat Nov 20 13:08:53 PST 2010


On Sat, Nov 20, 2010 at 1:29 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

> If you want to capture a not-effectively-final local variable in a closure,
> then one of the following two things has to happen:
> a) The lifetime of the variable must be extended to the lifetime of the
> closure
> b) The lifetime of the closure must be shortened to the lifetime of the
> variable.
>

The JLS doesn't talk about the lifetime of local variables because, like all
variables and dynamically allocated objects, they simply cease to exist when
they can no longer be referenced.  There would be no need to change that.


More information about the lambda-dev mailing list