[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hashCode question (was Re: Silly Java question)
From: |
Per Bothner |
Subject: |
Re: hashCode question (was Re: Silly Java question) |
Date: |
Tue, 27 Dec 2005 11:14:08 -0800 |
User-agent: |
Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324) |
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.
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.
--
--Per Bothner
address@hidden http://per.bothner.com/
Re: Silly Java question, Roman Kennke, 2005/12/27