I am so sure this is not a duplicate although heading may seems used.Please take a look
On what basis hashcode is calculated in JAVA???
On the basis of current state??? I don't think so.
Here is the code:
initTest inttt2 = new initTest();// this initTest has params: int x and String str
inttt2.str = "i am object1";
inttt2.x = 374892762;
System.out.println(inttt2.hashCode()); // print say 12345
inttt2.x = 938745;
inttt2.str = "i am object22222222";
System.out.println(inttt2.hashCode()); // still print 12345
So here is the question: Do hashcode depends on location in memory if it does not depends on current state???
Do hashcode remains same no matter how much you alter the object??
I am not an expert in data structures but one question is bothering me very much.
This hashcode(particularly Object's native) function have to return an hash value within range of integer so what options do it have other than calculation by its attributes.