Feature suggestion: Add static equals methods to Float and Double
some-java-user-99206970363698485155 at vodafonemail.de
some-java-user-99206970363698485155 at vodafonemail.de
Fri Jan 4 23:11:09 UTC 2019
To test whether primitive float or double values are equal according to `Float.equals` and `Double.equals` you either have to create wrapper instances for them (possible performance decrease), use the respective static `compareTo` (verbose) or have to use the appropriate methods (`floatToIntBits` / `doubleToLongBits`) (verbose and error-prone since you could confuse them with the other conversion methods).
It would be good to provide static methods for testing for equality of the primitive values:
// In Float.java
public static boolean equals(float a, float b) {
return Float.floatToIntBits(a) == Float.floatToIntBits(b);
}
// In Double.java
public static boolean equals(double a, double b) {
return Double.doubleToLongBits(a) == Double.doubleToLongBits(b);
}
This would be very convenient for developers and prevent them from writing (possibly faulty) code for this themselves.
More information about the core-libs-dev
mailing list