Tony Morris wrote:
The value returned by hashCode doesn't have to remain the same during the program's lifetime.
Assuming you mean "object lifetime", yes it does, otherwise, the contract is broken. "Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, ..."
Hello Tony,
I did mean "object lifetime". Yet the ellipsis you omited for the hashCode API says:
provided no information used in equals comparisons on the object is modified.. This is exactly what is was refering:
My full quote:
The value returned by hashCode doesn't have to remain the same during the [object's] lifetime. The hashCode of a class should be computed using the same field values that the equals method uses to determine object equality. So, if the internal state of an object changes so should its hash value.
I do suggest you read the full context before stating that someone is wrong.
...Ariel