First round of java.util.Objects for code review (bug 6797535)
Eamonn McManus
Eamonn.McManus at Sun.COM
Fri Oct 9 09:36:20 UTC 2009
> The spec, you mention, refers to the instance method equals(), but here
> we are talking about static helpers.
The difference between Marek's suggestion and Joe's is what happens when
the equals(Object) method of a or b returns true for a null argument, and
that is what I was saying violates the spec.
Éamonn McManus · JMX Spec Lead · http://weblogs.java.net/blog/emcmanus
Ulf Zibis wrote:
> 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
>
>
More information about the core-libs-dev
mailing list