Why isn't the `Number` interface extending `Compa...
# language-proposals
h
Why isn't the
Number
interface extending
Comparable
? Being a number always superimposes an ordering imho.
l
Because of NaN?
h
I see the argument, but in fact
Double
is implemented as
Double private constructor() : Number(), Comparable<Double>
in the standard library, which somehow argues against it. AFAIK all other subtypes of
Number
(excluding Double and Flot) don't have a NaN value
l
You're right. I guess it's because Java's
Number
doesn't either? Regardless, it's pretty easy to make your own comparator that does a conversion beforehand.
f
The number interface is generally useless.
r
I would guess because because numbers aren't meant to be comparable against all other number types (that is, `Int`s should only be compared to `Int`s, not to `Number`s) and they didn't want some sort of
Number<T: Number<T>>
.
As to why, I would guess because most of the numbers are primitives, so generic constraints don't really work at the byte code level, but I could be wrong.
b
Also keep in mind that not all sets of numbers are ordered, such as complex numbers
r
True, though I think that's a bit too theoretical for this since complex numbers don't really fit the
Number
interface anyway.