Friday, April 15, 2016

Contract for the Equals method

Reflexive:

x.equals(x) should always be true for every x that is non-null.

Symmetric:

For any non-null x and y references, x.equals(y) should return true if and only if y.equals(x) is true

Transitive:

For any x, y and z non-null references, if x.equals(y) and y.equals(z) both return true, then x.equals(z) should also return true.

Consistent:

Multiple invocations of x.equals(y) should always return the same value, provided no information used in the equals comparisons is modified.

x.equals(null) should return false.