What is the meaning of this?
Peter Levart
peter.levart at gmail.com
Thu Jan 28 13:46:44 PST 2010
On Thursday 28 January 2010 20:19:05 Joshua Bloch wrote:
> Entirely banning the use of this in lambada expressions is a very bad idea.
> It amounts to throwing out the baby with the bath water. If you need to get
> your hands on the function object created by a lambda expression, but
> this doesn't
> provide it, you're out of luck.There is no general-purpose workaround. And
> people will be tempted to use workarounds that aren't thread-safe, such as
> stashing the lambda in a field.
>
Local variables are perfectly thread-safe:
void method()
{
final #int(int) factorial = #(int i)(i == 0 ? 1 : i * factorial.(i - 1));
}
This can be made allowed, since evaluation of lambda expression is not using the value of final
variable being defined, it's just capturing it and there are no recursive type resolving problems
here.
Peter
More information about the lambda-dev
mailing list