Checked exceptions within Block<T>
Remi Forax
forax at univ-mlv.fr
Wed Jan 16 02:09:29 PST 2013
On 01/16/2013 09:02 AM, Neal Gafter wrote:
> On Tue, Jan 15, 2013 at 9:41 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>> Dynamic detection is used, for example, to ensure that someone doesn't
>> [...] call it after the variable to be mutated has gone out of scope.
>>
> You can't (syntactically) name a variable that is out of scope, so there is
> no way to mutate it if it is out of scope.
You can capture it in a lambda and call the lambda that will mutate the
variable out of the scope.
Runnable r;
{
int a = 0;
r = () -> { a = 1; };
}
r.run();
so it depends if you consider that a still exist or not when you call run.
> My point is that variable scope is a lexical concept, and lifetime is a dynamic concept.The variable
> "comes in and out of scope" every time a lambda in the scope of the
> variable is executed - and then it is in scope on some threads but not in
> others. It is a category error to suggest any dynamic checking would be
> helpful.
yes.
lambdas that capture and mutate a local variable need at least to be
biased to the current thread and if you consider that accessing to
mutating a local variable out of it scope is not legal you need another
check.
>
> On the other hand the scope and lifetime of control constructs
> (specifically the control targets associated with break, continue, and
> return) do have some association.
>
Rémi
More information about the lambda-dev
mailing list