Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail From: "Patricia Shanahan" Subject: Re: hashCode Message-ID: <5027FE12.56710.calajapr@time.synchro.net> X-Comment-To: Eric Sosman Newsgroups: comp.lang.java.programmer In-Reply-To: <5027FE12.56709.calajapr@time.synchro.net> References: <5027FE12.56709.calajapr@time.synchro.net> X-FTN-AREA: COMP.LANG.JAVA.PROGRAMMER X-FTN-MSGID: 1:261/38 41643f0c X-FTN-REPLY: 1:261/38 c7b83e6a Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] Lines: 37 Date: Sun, 12 Aug 2012 20:00:37 GMT NNTP-Posting-Host: 69.21.70.65 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1344801637 69.21.70.65 (Sun, 12 Aug 2012 15:00:37 CDT) NNTP-Posting-Date: Sun, 12 Aug 2012 15:00:37 CDT Organization: tds.net Xref: csiph.com comp.lang.java.programmer:17762 To: Eric Sosman From: Patricia Shanahan On 8/12/2012 10:59 AM, Eric Sosman wrote: > On 8/12/2012 12:40 PM, Patricia Shanahan wrote: >> [...] >> I think there are two reasonably usable ways of handling this issue. One >> is the current arrangement, in which every class has a hashCode that is >> expected to be usable for selecting a hash table bucket. >> >> Keeping hashCode as an Object method but making it useless for bucket >> selection unless overridden would not be a good alternative. >> >> A more reasonable alternative would be to have hashCode as the only >> member of a HashKey interface that would be implemented by every class >> whose objects are intended to be suitable for use as has keys. Those >> objects that have a hashCode would still have to have a usable one, but >> some classes would not implement HashKey and not have a hashCode at all. > > Ugh. So if J. Random Programmer is too lazy or unimaginative to > write hashCode(), that means I can't use his class as a HashMap key, > or even put instances in a HashSet? Ugh, again. > > (And, no: I don't think a HashCalculator interface along the lines > of Comparable would save the day.) > I'm not saying that it would be better than the current situation, just better than having hashCode implementations that appear to be there, but in practice must not be used for hash bucket selection. Patricia --- BBBS/Li6 v4.10 Dada-1 * Origin: Prism bbs (1:261/38) --- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24