Compilation of lambda in an interface, do we have a plan ?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed May 22 03:29:46 PDT 2013
I'm not sure as to why this hasn't been fixed by Robert recent changes -
Robert?
I believe the plan is to go static for the first example, and default
_private_ for the second.
Maurizio
On 22/05/13 08:45, Remi Forax wrote:
> 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-experts
mailing list