recursive lambda as a local variable

Dan Smith daniel.smith at oracle.com
Wed Sep 11 10:36:54 PDT 2013


I'm pretty sure that's just the way things work.  Fields can refer to themselves in their initializers; local variables cannot.  (This is because fields always have a value (possibly null), while local variables can't be accessed before initialization.)

You could try the same thing with an int:

int i = i+1;

—Dan

On Sep 11, 2013, at 10:37 AM, Zhong Yu <zhong.j.yu at gmail.com> wrote:

> This compiles: (b106)
> 
>    class Test
>    {
>        Runnable r = ()->r.run();
>    }
> 
> but this doesn't:
> 
>    void test()
>    {
>        Runnable r = ()->r.run();
>    }
> 
> is that intentional or a bug?
> 
> Zhong Yu
> 



More information about the lambda-dev mailing list