JDK-4414323 : java.lang.Number should implement java.lang.Comparable.
Type:Enhancement
Component:core-libs
Sub-Component:java.lang
Affected Version:1.4.0
Priority:P4
Status:Closed
Resolution:Not an Issue
OS:solaris_7
CPU:generic
Submitted:2001-02-12
Updated:2001-11-01
Resolved:2001-11-01
Description
All of the classes that extend java.lang.Number also implement
java.lang.Comparable. As all numbers are comparable, shouldn't
the class Number implement Comparable?
Comments
EVALUATION
All "numbers" are not comparable; comparable assumes a total ordering of numbers is possible. This is not even true of floating-point numbers; NaN (not a number) is neither less than, greater than, nor equal to any floating-point value, even itself. {Float, Double}.compare impose a total ordering different from the ordering of the floating-point "<" and "=" operators. Additionally, as currently implemented, the subclasses of Number are only comparable to other instances of the same class. There are other cases, like complex numbers, where no standard total ordering exists, although one could be defined. In short, whether or not a subclass of Number is comparable should be left as a decision for that subclass.
###@###.### 2001-11-01