commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [lang] Should ObjectUtils.Null provide toString(), hashCode() & equals() ?
Date Wed, 03 Sep 2003 14:33:07 GMT

As toString is meant to be a convenience method, the default
Object.toString seems to be more useful. Is there any positive reason to
actually return null for toString?

Having Null being equal to null seems clever, but could cause issues I
think. It's not symmetric as null.equals(..) falls over. So really
equals(null) should throw an NPE as null.equals does.

On hashCode... is there any benefit?

I think 2 of the ideas make semantic sense, but I'm not sure they'd
actually help anyone.

The equals() could help people, but doesn't make semantic sense :)

Hen

On Wed, 3 Sep 2003, Jason Dillon wrote:

> Should ObjectUtils.Null provide toString(), hashCode() & equals() as
> such:
>
>     public String toString() {
>        return null;
>     }
>
>     public int hashCode() {
>        return 0;
>     }
>
>     public boolean equals(final Object obj) {
>        if (obj == this) return true;
>        return (obj == null || obj.getClass() == getClass());
>     }
>
> ?
>
> --jason
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message