As far as I know Object.hashCode() class is native.
Correct.
I particularly interested in: is there any randomization in this method?
The hashcode returned by Object.hashCose()
IS typically based on a machine address of the object at some time during its lifetime. The address, and hence the hashcode may be influenced by a variety of random factors, depending on the application.
However, this does not mean that the hashcodes are random. In fact, if you allocated two objects one after the other and immediately got their hashcodes, it is likely that there will be a strong correlation between the two hashcodes.
Likely ... but not guaranteed.
Correct me if I am wrong but when we call == operator we compare references of such objects.
Correct.
... alias compare hashcodes.
If you are saying that ==
involves hashcodes, that is INCORRECT. ==
is implemented by comparing the current machine addresses of the objects.
So do we always get false because of randomization involved into Object.hashCode() method?
No. In your example, you get false
because the object references are different!
In fact, it is possible for two distinct Object
instances to have the same hashcode.
o1 == o2 IMPLIES o1.hashcode() == o2.hashcode() is TRUE
o1.hashcode() == o2.hashcode() IMPLIES o1 == o2 is FALSE