[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hashCode question (was Re: Silly Java question)

From: Michael Barker
Subject: Re: hashCode question (was Re: Silly Java question)
Date: Wed, 28 Dec 2005 20:40:46 +0000

On Tue, 2005-12-27 at 11:14 -0800, Per Bothner wrote:
> Michael Barker wrote:
>   >>From the equals() code, its applicable in this case:
> > 
> >     // The toString output must match.
> >     if (! toString().equals(((KerberosPrincipal)that).toString()))
> >       return false;
> In your message you did phrase things in terms of general contracts.

True, my fault, I jumped context.

> More to the point: Using toString in the implementation of equals
> seems like a bad idea.  The only rationale I can think of is as a
> hack to try to catch that the actual classes match.  But it seems
> an unreliable and inefficient method to do so.
> I'd go further: Implementing equals in terms of toString is a bug.
> One should be able to change toString before better output or
> debuggability without breaking equals.

I agree, and the hashCode() method should follow suite.

Michael Barker.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]