Dear all,
In the
test CD of K&B book, there is one example:
One of the answers in the CD is
I wonder if this is correct? Because according the the contract between equals and hashCode, "but equals() and hashCode() are bound together by a joint contract that specifies if two objects are considered equal using the equals() method, then they must have identical hashcode values."
In this case, if we have 2 object A and B. Supporse that they have the same code, but A.bal = 2, A.rate = 3, B.bal = 3, B.rate = 2. In this case, equals() return true but these objects do not have the same hashCode, which violate the contract.
Is this answer correct???