lambda bugs - trouble with `this` in lambda body in default method
Stuart Marks
stuart.marks at oracle.com
Mon Sep 9 17:46:46 PDT 2013
Nice bugs! These reproduce on b106, which was recently released as the
official JDK 8 Developer Preview build.
Well, more precisely, the first example still crashes, and the second
example crashes at runtime with a VerifyError instead of printing
"null". Still a bug though obviously.
I've filed a bug which should eventually appear here:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8024497
Thanks,
s'marks
On 9/6/13 8:07 PM, Zhong Yu wrote:
> This code crashes javac (jdk8 ea build 105)
>
> public interface Foo
> {
> default Runnable getAction()
> {
> return ()->{
> System.out.println(this);
> };
> }
> }
>
> Insert a random line, the code compiles; but at runtime, `this`
> evaluates to null
>
> public interface Foo
> {
> default Runnable getAction()
> {
> return ()->{
> int x = 0; // a random line
> System.out.println(this); // prints "null"
> };
> }
>
> public static void main(String[] args)
> {
> Foo foo = new Foo(){};
> foo.getAction().run();
> }
> }
>
>
> Zhong Yu
>
More information about the lambda-dev
mailing list