Bug 114780 - [DCR] warn on non conformant equals methods
Summary: [DCR] warn on non conformant equals methods
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-02 11:34 EST by Maxime Daniel CLA
Modified: 2005-11-02 11:34 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2005-11-02 11:34:33 EST
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).