S
Sideswipe
So, I have read the SDN entry of why Number does not implement
Comparable
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4414323
And while I agree with their thinking I disagree with their approach.
Not all Numbers are 'Comparable' such as NaN (which is one of their
motivational cases). However, when you look up the behavior of
compareTo() in Float -- no such special condition exists for the case
of NaN
While some numbers are not comparable, I argue that the numbers used
in Java (with the exception of NaN) are comparable. So, Double d =
10.12 and Integer x = 11 ARE comparable. X is clearly larger.
For me, it seems that a better approach would be to have Number
implement Comparable in the class signature but not actually DO the
implementation. That way, in the event of NaN and such, implementing
methods can simply throw exceptions (which seems far more appropriate
than what Float.compareTo(Float.NaN) produces now -- which is
int result = new Float(10).compareTo(Float.NaN);
System.out.println(result);
-1
Only special number cases are not comparable.
Thoughts, anyone? I fully realize I may bring out the worst in people
with this question
Christian Bongiorno
http://christian.bongiorno.org
Comparable
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4414323
And while I agree with their thinking I disagree with their approach.
Not all Numbers are 'Comparable' such as NaN (which is one of their
motivational cases). However, when you look up the behavior of
compareTo() in Float -- no such special condition exists for the case
of NaN
While some numbers are not comparable, I argue that the numbers used
in Java (with the exception of NaN) are comparable. So, Double d =
10.12 and Integer x = 11 ARE comparable. X is clearly larger.
For me, it seems that a better approach would be to have Number
implement Comparable in the class signature but not actually DO the
implementation. That way, in the event of NaN and such, implementing
methods can simply throw exceptions (which seems far more appropriate
than what Float.compareTo(Float.NaN) produces now -- which is
int result = new Float(10).compareTo(Float.NaN);
System.out.println(result);
-1
Only special number cases are not comparable.
Thoughts, anyone? I fully realize I may bring out the worst in people
with this question
Christian Bongiorno
http://christian.bongiorno.org