On Oct 17, 10:45 am, Reinier Zwitserloot <reini...@gmail.com> wrote:
> I never said Josh changed his views. I said version 1.0 contained a
> bug. Which that second snippet clearly shows: Using instanceof like
> that, _unless_ some documentation explicitly states that cross-type
> equality is intended (and thus also locks down any subclasses from
> adding equality-relevant state), cannot result in a transitive equals
> method.
>

Okay from your earlier post:

> > > Simple enough. But wrong. In the second edition, the instanceof check
> > > was revised to this:
>
> > > if (o.getClass() != this.getClass()) return false;
>

>From this I concluded that you wanted to say that Bloch recommended
"instanceof" in the first edition and getClass() in the second
edition. This is not true since his Point example in the second
edition is:

----
public class Point {
    private final int x;
    private final int y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override public boolean equals(Object o) {
        if (!(o instanceof Point))
            return false;
        Point p = (Point)o;
        return p.x == x && p.y == y;
    }

    ...  // Remainder omitted
}
----

As readers of the book will know Bloch uses composition in order to
handle new value components.


Kind regards,
Jacob Grydholt

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javapo...@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to