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

Robert Field Robert.Field at oracle.com
Wed May 22 11:27:53 PDT 2013


On 5/22/13 6:29 AM, Remi Forax wrote:
> On 05/22/2013 12:29 PM, Maurizio Cimadamore wrote:
>> I'm not sure as to why this hasn't been fixed by Robert recent 
>> changes - Robert?
>
> It seems that Robert as done it's change on jdk8/tl/langtools  and not 
> lambda/lambda/langtools,
> so the version of javac from jdk8/tl is more recent that the one from 
> lambda/lambda/langtools.

Making interface lambda methods static where possible was done in lambda 
weeks back.

There are some other changes which have not been sync'ed back to lambda.
>
>>
>> I believe the plan is to go static for the first example, and default 
>> _private_ for the second.
>
> Ok,
> I think that in that case lambda in class should be translated the 
> same way.
> Currently, a lambda that capture this but doesn't use super is not 
> translated to a static method.

The plan is
(1) for all lambda methods to be private.
(2) where there is no implicit/explicit this reference, the lambda 
method is static.
(3) otherwise the lambda method is an instance method (on interfaces 
this is called "default")

Where we are is:
(1) Implemented except for default methods, there is a VM bug that 
requires us to make them public for now.
(2) Implemented.
(3) Implemented.

-Robert


>
>>
>> Maurizio
>
> Rémi
>
>>
>> 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-observers mailing list