First round of java.util.Objects for code review (bug 6797535) (original) (raw)

Ulf Zibis Ulf.Zibis at gmx.de
Fri Oct 9 09:30:13 UTC 2009


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