capturing (or not) mutable local variables

Mark Mahieu markmahieu at gmail.com
Fri Nov 26 09:13:44 PST 2010


On 26 Nov 2010, at 10:58, Doug Lea wrote:
> 
> The workarounds like using 1-slot arrays add a level of
> indirection to subvert the shallow-only provision.
> Which seems tolerable.

It's tolerable if the workaround is employed with a good understanding of its limitations, but it has become a common approach to simple inconveniences with final variables used in relatively innocuous contexts.  My fear is that it's a workaround which will find itself used in far less tolerant situations through the simple virtues of being well known and long established.

So the following kind of approach...

> However, it does suggest
> that if there were better syntax support for safe
> workarounds, people might be happier to use them.
> Maybe @ThreadLocal could trigger this transformation?
> 
>   class C {
>     void f() {
>        @ThreadLocal int i = 0;
>         ... #{ ... ++i; ... }
>      }
>   }
> 
> -Doug


... is one I see as a (conceptually) neat alternative to the two extremes this discussion has polarised around so far.

Lambda does present a very rare opportunity to offer a different approach and have it noticed by a wide audience.


Cheers,

Mark



More information about the lambda-dev mailing list