Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 28 Aug 2012 03:06:20 -0500 Date: Tue, 28 Aug 2012 01:06:19 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: hashCode References: <563f186a-edb3-4311-ae48-3af7decfce2c@googlegroups.com> <6ac6c252-c370-4f74-b29d-ce5368019977@googlegroups.com> <502598d0$0$287$14726298@news.sunsite.dk> <5028191b$0$290$14726298@news.sunsite.dk> <50317b03$0$281$14726298@news.sunsite.dk> <503bfd0f$0$282$14726298@news.sunsite.dk> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 35 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.200.172 X-Trace: sv3-U1nfbAojxYrD83ydKZE1AXccbMAxCJfDTvD55ptvJOtRGLXEzRiKjzRcdyRWKNV8Ic9YrrZEwO+CCfb!UyilkNrMzzYiLudpp7/RG4VmxsAl3px36qVQe9toilXMjA4GQ+Nstw7uIMMSUzLBzDWDbI06nip0!+WtBs6hk0aMxMlTAw/4ZJgoWH7FLj0TTphc7/iX6qGpJ59M= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2920 Xref: csiph.com comp.lang.java.programmer:18351 On 8/27/2012 9:19 PM, markspace wrote: > On 8/27/2012 6:58 PM, Patricia Shanahan wrote: >> On 8/27/2012 5:03 PM, markspace wrote: >> ... >>> For example, in C, one can always hash based on memory address. In Java >>> we don't have that option, so hashcode() takes the place of the >>> intrinsic property of an address. >> ... >> >> In Java we have System.identityHashCode() which provides an address-like >> hash code for any object. > > > I think System.identityHashCode() is the (same as the) default > implementation for Object::hashCode(), yes? Yes, but it could have been written, with a slightly different explanation, without putting hashCode() in Object. > > So there's a small bit of evidence in support of the idea that > Object::hashCode() is meant to mimic the idea of just hashing on address. I don't think you need such indirect evidence: "As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.) " [From the Object API documentation.] Patricia