Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12466
| Date | 2012-02-27 20:57 -0500 |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Additional logging questions |
| References | (2 earlier) <XnsA005ED51BFCF7jpnasty@94.75.214.39> <jif6ua$3cm$1@news.albasani.net> <XnsA0069221E7830jpnasty@94.75.214.39> <jigr8v$jhh$1@news.albasani.net> <XnsA006D3D7FBB0Bjpnasty@94.75.214.39> |
| Message-ID | <4f4c348e$0$292$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
On 2/27/2012 8:48 PM, Novice wrote:
> Lew<noone@lewscanon.com> wrote in news:jigr8v$jhh$1@news.albasani.net:
>> But wait! 'hashCode()', which is a shortcut for 'equals()' (well,
>> really for "not equals()"), doesn't know anything about those fields
>> yet! It will think objects are not equal when they really are.
>>
>> So you have to override 'hashCode()', too, using the same fields, so
>> that its result are consistent with 'equals()':
>>
>> @Override public int hashCode()
>> {
>> return owner.hashCode() * 31 + color.hashCode();
>> }
>>
> Just curious: why multiply the owner.hashCode() by 31? There's no
> significance to the 31 is there? Why not just add the two hashCodes
> together without multiplying one of them first? That would be just as
> good, right?
Actually not.
Some numbers are better than others (no multiply means 1).
You should go for a prime.
31 is often used.
But there are other good numbers.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Additional logging questions Novice <novice@example..com> - 2012-02-27 02:02 +0000
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 21:08 -0500
Re: Additional logging questions Novice <novice@example..com> - 2012-02-27 04:12 +0000
Re: Additional logging questions Lew <noone@lewscanon.com> - 2012-02-26 22:13 -0800
Re: Additional logging questions Novice <novice@example..com> - 2012-02-27 19:14 +0000
Re: Additional logging questions Lew <noone@lewscanon.com> - 2012-02-27 12:32 -0800
Re: Additional logging questions Lew <noone@lewscanon.com> - 2012-02-27 13:06 -0800
Re: Additional logging questions Novice <novice@example..com> - 2012-02-28 01:48 +0000
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 20:57 -0500
Re: Additional logging questions Lew <noone@lewscanon.com> - 2012-02-27 23:51 -0800
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 20:50 -0500
Re: Additional logging questions Lew <noone@lewscanon.com> - 2012-02-27 23:57 -0800
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 20:45 -0500
Re: Additional logging questions Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-02-28 01:52 -0600
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-28 17:20 -0500
Re: Additional logging questions Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-28 20:26 -0400
Re: Additional logging questions Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 20:34 -0500
Re: Additional logging questions Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-27 12:36 -0800
Re: Additional logging questions Novice <novice@example..com> - 2012-02-28 01:43 +0000
csiph-web