On Wed, 2008-04-30 at 10:55 +0200, Petr Nejedly wrote:
> 
> BTW: There's _no_ semantic change anyway, taking into account the
> semantics
> of Object.equals (as Object is the direct superclass).
> Both implementations would return false.
> Anyway delegating to super implementation in case it will always
> return false
> still makes the code obscure and consider my implementation (in
> josm-ng) clearer:
> 
>     public @Override boolean equals(Object obj) {
>         if (id == 0) return obj == this;
>         if (obj instanceof OsmPrimitive) { // not null too
>             return ((OsmPrimitive)obj).id == id && obj.getClass() ==
> getClass();
>         }
>         return false;
>     }

I'm perfectly fine with doing that.  Could we try and make it a bit
readable, though?  What about this:

public @Override boolean equals(Object obj)
{
        // Unassigned id, only equal if exact same object
        if (id == 0)
                return obj == this;
        // Never equal to different types
        if (!(obj instanceof OsmPrimitive)) // covers null
                return false;
        // Isn't this somewhat redundant with the above?
        // How about an explicit null check along with this:
        if (this.getClass() != obj.getClass())
                return false;
        return ((OsmPrimitive)obj).id == id;
}

-- Dave


_______________________________________________
josm-dev mailing list
[email protected]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/josm-dev

Reply via email to