Open Hixie opened 8 years ago
The problem with Comparable
is that the type parameter occurs contravariantly. We allow you to assign a Foo<int>
to a Foo<num>
variable because it's safe when the type parameter occurs in covariant positions, and most of them do.
For Comparable
its the other way around, a Comparable<num>
can be used as a substitute for a Comparable<int>
everywhere, but the type system isn't able to recognize that.
If we get variance annotations, we can make Comparable
contravariant, so that Comparable<num>
is assignable to Comparable<int>
. Until that, there is no chance of any change.
That's because it implements
Comparable<num>
.It's 1am here, so I might be completely off, but I don't see a good solution here. You want to be able to compare doubles with integers, and if
int
implementedComparable<int>
it would restrict thecompareTo
toint
s.