Override hashCode () method problem

Category: Java Related
 
annyhnchshhf
2010-09-12 01:41:38

Sponsored Links
Why then override hashCode () when you want to
int result;
result = getRes (). getResId (). hashCode ();
result = 39 * ; result * getRes (). hashCode ();
return result;
39 What does it mean? ?
This value is fixed or can change! !
heroes online waiting .......

Sponsored Links

tensemy
2010-09-12 01:51:44
The design of this method is to ask how people consider.
You can design their own algorithms, as long as possible to avoid conflict.
gept123
2010-09-12 01:57:36
You can refer to the book Effective Java.
usually hashCode method of calculation:
int hashCode = prime number 1;
for each in all the member variables {
hashCode = hashCode * primes 2 + hash (member variables);
}

which, hash (member variables) according to the member variable x ; Type:
Object: x == null? 0: x.hashCode ();
native types: converted into the corresponding integer (long , float, double the value in bytes rather than turn)
luoyuea
2010-09-12 02:16:15
Your 39 is a prime number 2 in the formula. The reason to use prime numbers is to reduce the collision
guang453701381G45370
2010-09-12 02:29:28
Thank you! ! ! ! !
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.