The lack of consistency is even worse than you describe as the other comparison operators (>, <, >=, <=
) aren’t bothered about whether integer types match or not.
For example this compiles and runs fine:
fun main(args: Array<String>) {
val a = 0L
val b1 = (a >= 0)
val b2 = (a >= 0L)
println("b1 = $b1, b2 = $b2")
}
The problem was touched upon in this thread and is to do with the way the equals
method works (essentially the types have to be exactly the same) whereas the compareTo
method has overloads for comparing different integral types.
I don’t know what the best solution is to these problems, though allowing implicit widening conversions between the integral types was mentioned in that thread.