Community
Participate
Working Groups
The compiler currently raises a warning when an equals method overrides Object.equals(Object) without being marked with @Override (5.0 mode), or an error when its visibility is reduced. Implementing an equals method that has a reduced visibility and different semantics is still possible by using a different signature, aka using a parameter of a class more specific than Object. This can bring some confusion, such an equals method NOT being an override of Object.equals(Object). For example, the following code: class X { @Override public boolean equals(Object o) { return false; } boolean equals (X x) { return this == x; } public static void main(String args[]) { X x1 = new X(), x2 = x1; System.out.println(x1.equals(x2)); System.out.println(x1.equals((Object) x2)); } } displays: true false The compiler could raise a warning whenever a method is declared with the name equals that is not a proper override of Object.equals(Object).