capturing (or not) mutable local variables

Florian Weimer fweimer at bfk.de
Tue Nov 23 06:04:27 PST 2010


* Brian Goetz:

> In order to justify the complexity that these new features would
> generate, there needs to be a compelling use case.  When I explored
> this issue, I asked a number of people to write down a use case for
> this.  Every one wrote some form of:
>
>  int sum = 0;
>  list.forEach( #{ x -> sum += x.foo() }

With anonymous classes, it's used quite often for returning more
values than the signature of a callback function permits.

Can we at least add ObjectReference<T>, IntReference, LongReference et
al. to the JDK, and discourage abusing arrays for this purpose?

> In a parellel world, this idiom is irretrievably broken.

I fear that such an extreme focus on concurrent programming is rather
unhealthy for a general-purpose language.

-- 
Florian Weimer                <fweimer at bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99


More information about the lambda-dev mailing list