Method reference conversion

Remi Forax forax at univ-mlv.fr
Thu Dec 15 23:35:20 PST 2011


While it's possible to implement that, it will make equals slow because the VM packs the arguments in order to have fast call.

So it's unlikely that a lambda will inherits to something else that Object.

Cheers,
Rémi


Howard Lovatt <howard.lovatt at gmail.com> wrote:

>It would be nice if they were equal() even if !=
>
>On 16 December 2011 13:08, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>> Slight correction -- in this particular case (where the method reference
>> is a bound instance reference), it seems quite unlikely that these
>> references would be ==.  However, for static references and unbound
>> instance references, it is quite likely that they will be ==.  In any case,
>> it is unlikely the spec will make promises that are potentially expensive
>> to keep.
>>
>> On Dec 15, 2011, at 4:10 PM, Brian Goetz wrote:
>>
>> > Most likely outcome: no guarantees (such guarantees come with a cost)
>> but it is "highly likely" that method1 == method2.
>> >
>> > When we finish the implementation of functional interface conversion
>> we'll have a update.
>> >
>> > On Dec 15, 2011, at 3:35 PM, Uther wrote:
>> >
>> >> Hello. I have been reading this mailing list from long time but didn't
>> >> post anything right now since I'm not a Java expert, but I was
>> >> wonderning about Method references.
>> >>
>> >> Will every reference to a same method be converted to the same object?
>> >> Will the language specification tell something about it?
>> >>
>> >> For exemple:
>> >> Runnable method1 = this::myMethod;
>> >> Runnable method2 = this::myMethod;
>> >> System.out.println(method1 == method2); //returns true
>> >>
>> >> I'm not sure it is technicaly possible, but it would be very nice that
>> >> specification garantee that, it may allow to do interesting things like
>> >> a removeListener(this::myListener) after a
>> addListener(this::myListener);
>> >>
>> >
>> >
>>
>>
>>
>
>
>-- 
>  -- Howard.
>


More information about the lambda-dev mailing list