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, provided no information used in equals comparisons on the object is modified
Above statement is written at http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()
under hashcode contract.
I have a question on statement i.e
provided no information used in equals comparisons on the object is
modified
Even if we modify equals method still hashcode will return the same integer . so howcome hash code value is dependent on objects equal comparison.
You are adding extra meaning to that statement that is not there. It does not say that hashCode WILL change if the evaluation of equals changes. It is saying hashCode MAY change if the evaluation of equals changes. It is no longer guaranteed that the hashCode will be the same afterward. It is not wrong if it still is!
Remember
is a completely legal implementation of hashCode() that meets all requirements set forth by the documentation. hashCode is not, by definition, dependent on the equals calculation.
In practice they will of course be coupled together. Normally you override hashcode using all the same fields used as in equals because it is necessary that two different objects whose equals are true have the same hashCode. And return 1; wouldn’t play very nice with any of the classes that actually rely on the hashCode() method.
This more fully formed example of a legal implementation of hashCode that sometimes changes when equals changes, but not always, may be more clear.