Is the output of Object.hashCode()
required to be the same on all JVM implementations for the same Object?
For example if \"test\".hashCode()
No. The output of hashCode
is liable to change between JVM implementations and even between different executions of a program on the same JVM.
However, in the specific example you gave, the value of "test".hashCode()
will actually be consistent because the implementation of hashCode
for String
objects is part of the API of String
(see the Javadocs for java.lang.String and this other SO post).