Lambdas and serialization
Reinier Zwitserloot
reinier at zwitserloot.com
Fri Nov 12 01:24:09 PST 2010
Llewelyn, the equals method of comparator obviously compares.... the
comparator. Not objects in it. That would require a signature of equals(T a,
T B) which is something entirely different. And not in comparator today (and
thus, not in comparator, ever, or backwards compatibility would be broken).
As Greg said, A comparator need not be in sync with the T's own equals
method. However, if a class implements Comparable (a totally different
beast), then its own compareTo(other) method needs to return 0 when
.equals() says true.
--Reinier Zwitserloot
On Wed, Nov 10, 2010 at 3:29 PM, Alex Blewitt <alex.blewitt at gmail.com>wrote:
> 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