PPT Slide
As Regards the Identity of Objects. There are essentially four tests we can use to compare the identity of objects.
Reflexive: for any reference value x, x.equals(x) should return true.
Symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
Transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
Consistency: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false. (I.e., it wasn’t just a fluke.)
Why is this important? If you forget to create your own equals() method in a data class, you can still compare the objects with equals(), but the method ‘defaults’ to the most stringent equivalency test possible. That is, equals() will return true only if the two references point to the exact same location in memory.