recursive lambda as a local variable
Dan Smith
daniel.smith at oracle.com
Wed Sep 11 15:07:07 PDT 2013
On Sep 11, 2013, at 12:11 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> On Wed, Sep 11, 2013 at 12:36 PM, Dan Smith <daniel.smith at oracle.com> wrote:
>> I'm pretty sure that's just the way things work.
>
>> Fields can refer to themselves in their initializers;
>
> This part is kind of messy, for example
>
> public class Tmp
> {
> int x = x + 1; // fail. good.
>
> int y = this.y +1; // ok! allowed by JLS#8.3.2.3. probably spec bug.
>
> final int z;
>
> Tmp()
> {
> z = this.z+1; // ok! but forbid by JLS#16. probably javac bug
> }
> }
>
> With lambda it is more confusing
>
> public class Tmp
> {
> Runnable r1 = ()->r1.run(); // ok
>
> Runnable r2 = this.r2::run; // compiles... but
> NullPointerException at runtime
> }
>
> Zhong Yu
I see it's more complex than I thought.
I will investigate and probably generate a bug or two.
—Dan
More information about the lambda-dev
mailing list