Lambda recursive ...

Remi Forax forax at univ-mlv.fr
Fri Oct 19 06:52:50 PDT 2012


On 10/19/2012 03:41 PM, Ricky Clarkson wrote:
> The State of the Lambda #4 seems to suggest that this would apply to local
> variables too:
>
> 'Fortunately, by simply refining the "initialized-before-use" analysis that
> determines when variables can be referenced, ...'
>
> That seems to be talking about definite assignment, not the checking that
> applies to fields.

We (the EG) have decided to not change the initialized-before-use rule 
after all,
given recursive lambdas are a corner case and can also be written using 
method reference.

Rémi

> On Oct 19, 2012 10:20 AM, "Aleksey Shipilev" <aleksey.shipilev at oracle.com>
> wrote:
>
>> On 10/19/2012 05:09 PM, Boaz Nahum wrote:
>>> interface FactInt { int invoke(int i); }
>>>
>>>   FactInt factorial = i ->
>>>                  { return i == 0 ? 1 : i * factorial.invoke(i - 1); };
>>>
>>> But the compile (b61) says:
>>> error: variable factorial might not have been initialized
>>>
>>> How can I write recursive expression like this ?
>> Lambda can not capture the uninitialized local variable; the trick is to
>> use fields, in which case lambda will capture "this" or the reference to
>> static field [1].
>>
>> -Aleksey.
>>
>> [1]
>>
>> https://github.com/shipilev/jdk8-lambda-samples/blob/master/src/test/java/net/openjdk/lambda/FibonacciTest.java
>>
>>
>>



More information about the lambda-dev mailing list