Forums Register Login

Hash Code Implementation

+Pie Number of slices to send: Send
Hi everyone,
I need to implement hash code generation in my classe.
What are the best practices for doing this ?
I tried Apache lang HashCodeBuilder Class but i am getting different hashCode for same data(values of members of my classfor which i m generating hashCode.

Hoping for a reply soon

Thanks,
Nrapendra
+Pie Number of slices to send: Send
Hi there!

I've never heard of that class returning a different hash code for the same values before. Can you post the class/fields/values that you are trying to Hash?
+Pie Number of slices to send: Send
I have two xml files having same data in it.
Using both xml i m creating object(say o1 and o2) of my class (say Class A)
inside class A i have override the hashCode() method

int hashCode(){
HashCodeBuilder.reflectionHashCode(this, false);
}

members which i dont want to add in hash code generation i have made them transient.

Now when i m comparing hashCode of o1 and o2 ,i m getting different hashCode
+Pie Number of slices to send: Send
Hi
I could not understand your problem .Can you give your code here.
+Pie Number of slices to send: Send
Are you calling hashCode() on the HashCodeBuilder? If so, you shouldn't - it returns the hash code of that object, not the created hash code. There is another method (toHashCode() I believe) for that.
+Pie Number of slices to send: Send
Hi
I tried your problem and got the hash codes same for both the objects .Check it out.


I have done it using digester of apache.
[ November 20, 2008: Message edited by: Martijn Verburg ]
+Pie Number of slices to send: Send
Output was
collection.practice.hello@1201a25
digester3=collection.practice.hello@94948a
k =23273
df = 23273
hash codes are equasl
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1842 times.
Similar Threads
hashcode
UUID Uniqueness across JVMs
hashCode() from Object
which code is hashcode
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:14:00.