Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(compareTo() == 0) != equals() #18

Open
GoogleCodeExporter opened this issue Oct 9, 2015 · 1 comment
Open

(compareTo() == 0) != equals() #18

GoogleCodeExporter opened this issue Oct 9, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
BigDecimal d = new BigDecimal("4.0");
BigDecimal e = new BigDecimal("4.00");

System.out.println(d.compareTo(e) == 0); //true
System.out.println(d.equals(e)); //false

From the Comparable.compareTo documentation:
It is strongly recommended, but not strictly required that (x.compareTo(y)
==0) == (x.equals(y)). Generally speaking, any class that implements the 
Comparable interface and violates this condition should clearly indicate 
this fact. The recommended language is "Note: this class has a natural 
ordering that is inconsistent with equals." 

We need an annotation that clearly denotes that the result is inconsistent 
with equals.  I recommend @InconsistentWithEquals.

Original issue reported on code.google.com by [email protected] on 14 Aug 2009 at 7:16

@GoogleCodeExporter
Copy link
Author

To explain further since some collections do not properly handle Comparables 
that 
are inconsistent with equals, tools can issues warnings in those cases.  Such 
as:
SortedSet<BigDecimal> set = new TreeSet<BigDecimal>();
should causes a warning if the tool is configured for that check.

Original comment by [email protected] on 14 Aug 2009 at 7:23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant