You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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 issue reported on code.google.com by
[email protected]
on 14 Aug 2009 at 7:16The text was updated successfully, but these errors were encountered: