4 ms·
https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html https://docs.oracle.com/javase/8/docs/api/java/math/BigDecim... > Note: care should be exer
by shagie 2y ago
https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html https://docs.oracle.com/javase/8/docs/api/java/math/BigDecim...
> Note: care should be exercised if BigDecimal objects are used as keys in a SortedMap or elements in a SortedSet since BigDecimal's natural ordering is inconsistent with equals. See Comparable, SortedMap or SortedSet for more information.
https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#equals-java.lang.Object- https://docs.oracle.com/javase/8/docs/api/java/math/BigDecim...
> Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).
equals remains object comparisons.
Consider the problem if `2.0` and `2.00` returned true for equals call and they were keys to a HashMap - you'd only be able to put one of them in there.
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/HashMap.java#L642 https://github.com/openjdk/jdk/blob/master/src/java.base/sha...