The trap is quite simple: you did not redefine equals(Object) , you introduced another equals(String) method. This method will not be used by any calls to the equals infrastructure for your object, since dynamic dispatch applies to the run-time type of only the object in which the method is called, and the static type of all method arguments is used to allow the signature of the method at compile time.
If you βfixβ it to equals(Object) , but save the logic, then you broke the equals contract because you do not satisfy the symmetry property: if another string is compared with your object via String.equals(yourObject) it will return false, and you will you cannot influence it. This is a limitation of using the Java one-time send mechanism to determine the equality relationship.
Fortunately, the enumerations already prevent you from doing this with hardcoding equals and hashCode and make them final.
source share