Am 09.10.2009 10:56, Eamonn McManus schrieb:
Hi,

Marek Kozieł wrote:
>> +    public static boolean equals(Object a, Object b) {
>> +        return (a == b) || (a != null && a.equals(b));
>> +    }
>
> Hello,
> I would suggest other implementation of equals method:
>
>     public static boolean equals(Object a, Object b) {
>         if (a == null) return (b == null ? true : b.equals(null));
>         if (b == null) return a.equals(null);
>         return a.equals(b);
>     }
>
> This one could cover case when null is considered as object in object
> equals method [...]

An equals implementation that can return true when its argument is null violates its contract since it is not symmetric. In fact, the spec of Object.equals specifically says that the method must
return false when the argument is null.


The spec, you mention, refers to the instance method equals(), but here we are talking about static helpers.

But anyway, I don't understand the point of Marek's implementation.

-Ulf


Reply via email to