hashcode() overriding problem ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mohan_seenippandian
Posted On:   Saturday, September 25, 2004 04:36 AM




Hi

In the following code

			
public int hashCode(){
int result = 17;
result = 31*17 + (int)(area ^ (area >>> 32));
return result;

}


area is long data type, why should i use like this?

what would be the problem if i don't use the shifting and XOR operator?



Re: hashcode() overriding problem ?

Posted By:   Stephen_Ostermiller  
Posted On:   Wednesday, October 13, 2004 03:50 AM

If you are hashing your objects by their area, have you considered writing your function like this?


public int hashCode(){
return (new Integer(area)).hashCode();
}


Creating a hash code from an integer is a problem that has already been solved.
About | Sitemap | Contact