I am trying to understand this koan:
@Koan
public void equalsMethodCanBeChangedBySubclassesToTestsIfTwoObjectsAreEqual() {
Object object = new Integer(1);
assertEquals(object.equals(object), true);
assertEquals(object.equals(new Integer(1)), __);
}
As far as I understand, since it objectis an instance of the class object, the method has .equals()not been overwritten and therefore checks the equality of the object.
If new Integer(1)creating a new instance, it must be a separate object object. Following my example, the correct answer should be false, but only truemakes this passage. Where is the error in my logic?
Edit: I understand that integers from -128 to 127 are cached. If my understanding of the object is objectcorrect (as indicated above), then it does not matter.
source
share