Compilation of lambda in an interface, do we have a plan ?

Remi Forax forax at univ-mlv.fr
Wed May 22 00:45:37 PDT 2013


The compiler doesn't like code like this:

public interface Foo {
   default void bar() {
     Runnable r = () -> {
       System.out.println(this);
     };
   }
}

in that case the lambda in bar can be compiled to a static method.

But what if the lambda calls a super method like this:
interface I {
   default void m() { }
}

public interface Foo extends I{
   default void bar() {
     Runnable r = () -> {
       I.super.m();
     };
   }
}

given that I.super.m() is translated to an invokespecial call and that
as far as I know invokespecial needs to be called in an instance method.

One possible translation is to translate the lambda to a default method
but given that a default method is public, an interface that extends
the interface may be able to override the code of the lambda
with another lambda declared in the class with the same signature
even if the two lambdas are unrelated.

does it means that the lambda in interfaces must be numbered knowing
the whole hierarchy ?

cheers,
Rémi



More information about the lambda-spec-observers mailing list