Discussion of why java.lang.Number does not implement Comparable
- From: Sideswipe <christian.bongiorno@xxxxxxxxx>
- Date: Thu, 26 Jul 2007 21:37:03 -0000
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
.
- Follow-Ups:
- Re: Discussion of why java.lang.Number does not implement Comparable
- From: Oliver Wong
- Re: Discussion of why java.lang.Number does not implement Comparable
- From: Eric Sosman
- Re: Discussion of why java.lang.Number does not implement Comparable
- From: Owen Jacobson
- Re: Discussion of why java.lang.Number does not implement Comparable
- From: Sideswipe
- Re: Discussion of why java.lang.Number does not implement Comparable
- Prev by Date: Giving away books -- proceeds ...
- Next by Date: Re: Java and avoiding software piracy?
- Previous by thread: Giving away books -- proceeds ...
- Next by thread: Re: Discussion of why java.lang.Number does not implement Comparable
- Index(es):
Relevant Pages
|