Nelz's Blog

Mah blogginess

Java Equals(...) Question

So, I’m playing around with the idea of creating a utility to test adherence to the Java "Equals Contract", and I came across something that I find ambiguous in the JavaDoc of java.lang.Object.equals(…).

It has to do with transitivity. The JavaDoc says this:

  • For any non-null 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.

That’s all well and good. But I’m trying to figure out the inverse of this rule.

Is it this?:

  • For any non-null reference values x, y, and z, if x.equals(y) returns false and y.equals(z) returns true, then x.equals(z) should return false.

… Or is it this?:

  • For any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns false, then x.equals(z) should return false.

… Or are those two logically equivalent?