Lambdas and serialization
Greg Dennis
gdennis at alum.mit.edu
Wed Nov 10 12:21:48 PST 2010
A PersonComparator need not be consistent with the Person.equals()
method, but if Person implements Comparable, it's compareTo method
should be consistent with equals.
Greg
> Date: Wed, 10 Nov 2010 14:29:11 +0000
> From: Alex Blewitt <alex.blewitt at gmail.com>
> Subject: Re: Lambdas and serialization
> To: Llewellyn Falco <isidore at setgame.com>
> Cc: "lambda-dev at openjdk.java.net" <lambda-dev at openjdk.java.net>
> Message-ID: <CE392E93-4374-4ACE-831E-1DA2B753CCE5 at gmail.com>
> Content-Type: text/plain; charset=us-ascii
>
> That can't be right. Consider a PersonComparator which just compares first names. There may be two Alexs, but that doesn't mean they are the same Person.
>
> Sent from my iPhone 4
>
> On 10 Nov 2010, at 13:16, Llewellyn Falco <isidore at setgame.com> wrote:
>
>> I just realized this is a mistake!
>>
>> Comparable will not work properly without the Equals method
>> being overridden.
>>
>> Namely, if you have two object a, b you will get
>> a.compareTo(b) == 0
>> but
>> a.equals(b) == false
>>
>> depending on your implementation this will fail!
>>
>> Llewellyn Falco
>> http:\\bit.ly\lambdas
>>
>> On Wed, Oct 27, 2010 at 4:00 AM, Maurizio Cimadamore <
>> maurizio.cimadamore at oracle.com> wrote:
>>
>>>
>>> btw: what happens with comparator? it's not a SAM (2 methods - compare,
>>>> equals), but seems to be a very wanted case for lambdas?
>>>>
>>>>
>>>>
>>> The definition of SAM does not take into account methods inherithed from
>>> java.lang.Object. Which means that Comparator<T> really has just one
>>> relevant target method and therefore can be used as the target of a SAM
>>> conversion.
>>>
>>> Maurizio
More information about the lambda-dev
mailing list