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.
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?
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
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.