Compilation of lambda in an interface, do we have a plan ?
Remi Forax
forax at univ-mlv.fr
Wed May 22 06:29:31 PDT 2013
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.
>
> 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.
>
> 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-experts
mailing list