Is the output of Object.hashCode() required to be the same on all JVM implementations for the same Object?
For example if "test".hashCode() returns 1 on 1.4, could it potentially return 2 running on 1.6. Or what if the operating systems were different, or there was a different processor architecture between instances?
No. The output of
hashCodeis 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 ofhashCodeforStringobjects is part of the API ofString(see the Javadocs for java.lang.String and this other SO post).