Discussion of why java.lang.Number does not implement Comparable

P

Patricia Shanahan

Sideswipe said:
Actually, what I had in mind was this:

public abstract class Number implements Comparable ....
// dont actually implement compareTo()

public class Float extends Number {

public int compareTo(Object otherNumber) {
if(otherNumber == Float.NaN)
throw new ArithmaticException("NaN is not comparable");
if(otherNumber instanceof Integer)
return this.floatValue() -
((Integer)otherNumber).intValue();
}

}

This is not the slickest example, but that's what I had in mind. And,
yes, the specific case is that I have a mixed collection of Numbers
that I need to order. What I argue for is to let all the subclasses
sort their own comparison problems out. I can see from further
postings that the issue is contentious enough to simply allow Sun's
implementation to stand.

Remember that you can sort using a Comparator<Number>. All you need is a
total order that makes sense in your context, among the things you
expect to find in your collection. You can limit it to the types you
intend to mix. If you don't expect to see a NaN, you can throw an
exception if you hit one.

Patricia
 
E

Eric Sosman

Patricia said:
[...]
Each poster is responsible for whatever words they choose to type, every
time they write an article. Nobody can force someone else to flame.

"Temptation, O Temptation!
Were we, I pray, intended
To shun, whate'er our station,
Your fascination splendid?
Or fall, whene'er we view you,
Head over heels into you?"
 
P

Patricia Shanahan

Eric said:
Patricia said:
[...]
Each poster is responsible for whatever words they choose to type, every
time they write an article. Nobody can force someone else to flame.

"Temptation, O Temptation!
Were we, I pray, intended
To shun, whate'er our station,
Your fascination splendid?
Or fall, whene'er we view you,
Head over heels into you?"

comp lang java newsgroups
many questions and answers
some pointless flaming

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top