Unexpected variable ... is already defined ...

Remi Forax forax at univ-mlv.fr
Wed Dec 26 06:55:33 PST 2012


On 12/26/2012 03:13 PM, Denis DEBARBIEUX wrote:
>>> If yes, can the inner function (that does the test) use the outer
>>> parameter event?
>> yes, you can capture the value of parameters and local variables if they
>> are effectively final (not assigned more than once).
> Thanks for your help.
>
> How can you set that the value of a parameter is /final/?
>
> /getStream().map(//final//event -> event.matchIfA(//_event//->
> "a".equals(//_event//.label))).forEach(System.out::println);/
> does not compile.

parameters or local variables are final if not assigned, you don't have 
to declare them final anymore,
see section 7 of 
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html

>
> According to my tests, they are not final by default.

they are not final, they acts as final.

>
> Denis
>

Rémi



More information about the lambda-dev mailing list