S
Sideswipe
This is a question that continues to bug me.
There is Number. Double, Float, Int ... all extends Number and then
implement Comparable independently.
I know plenty of Math geeks troll this group. I know why Number is not
Comparable, but number has methods like: "doubleValue()"
What I would love is something like:
public abstract class RealNumber<T> extends Number implements
Comparable<T> {
.....
}
public class Double extends RealNumber<Double> {
// impement comparable <double>
}
public class Integer extends RealNumber<Integer> {
// impement comparable <Integer>
}
That way I could do ... Set<RealNumber> someSet = new
TreeSet<RealNumber>();
I don't care which type they are, as long as they are all the same and
I can't do <Number> because they aren't comparable.
And, I already know I can do:
Set<Number> someSet = new TreeSet<Number>(new Comparator<Number>() {
int compare(Number a, Number b) {return a.doublValue() -
b.doubleValue());}
});
But this has the inherent flaw of precision issues between Integer
and, say Double that this would mask.
I am tempted to actually implement this exact solution for my problem
space through delegation but I am hesitant that there might be some
hidden number theory problem with this approach.
Thoughts?
Christian Bongiorno
http://christian.bongiorno.org
There is Number. Double, Float, Int ... all extends Number and then
implement Comparable independently.
I know plenty of Math geeks troll this group. I know why Number is not
Comparable, but number has methods like: "doubleValue()"
What I would love is something like:
public abstract class RealNumber<T> extends Number implements
Comparable<T> {
.....
}
public class Double extends RealNumber<Double> {
// impement comparable <double>
}
public class Integer extends RealNumber<Integer> {
// impement comparable <Integer>
}
That way I could do ... Set<RealNumber> someSet = new
TreeSet<RealNumber>();
I don't care which type they are, as long as they are all the same and
I can't do <Number> because they aren't comparable.
And, I already know I can do:
Set<Number> someSet = new TreeSet<Number>(new Comparator<Number>() {
int compare(Number a, Number b) {return a.doublValue() -
b.doubleValue());}
});
But this has the inherent flaw of precision issues between Integer
and, say Double that this would mask.
I am tempted to actually implement this exact solution for my problem
space through delegation but I am hesitant that there might be some
hidden number theory problem with this approach.
Thoughts?
Christian Bongiorno
http://christian.bongiorno.org