Compilation of lambda in an interface, do we have a plan ?
Remi Forax
forax at univ-mlv.fr
Wed May 22 11:51:25 PDT 2013
Hi Robert,
On 05/22/2013 08:27 PM, Robert Field wrote:
> 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.
It depends what you mean by 'where possible', i.e. where you draw the line.
As far as I understand, we only need to make the lambdas that do a super
non-static,
not all lambdas that capture 'this'.
I'm not very comfortable to have instance default method in interface
when a static method can work
(even if it's not very rational, private methods are no more overridable
that static ones).
>
> 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.
Ok.
>
> -Robert
cheers,
Rémi
>
>
>>
>>>
>>> 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