val a = 0.0
println(a > 0) // why no compile error here?
println(a == 0) // compile error
Just discovered there is no need to use 0.0 for double comparisons in non equals operators.
val a = 0.0
println(a > 0) // why no compile error here?
println(a == 0) // compile error
Just discovered there is no need to use 0.0 for double comparisons in non equals operators.
There’s no error with the former because it’s using the compareTo() method which has overloads for all the primitive numeric types.
However, the latter is using the equals() method which - to cut a long story short - gives an error unless the types of the expressions on either side of the equals sign are the same.
This is an unsatisfactory situation and we had a long discussion about it recently in this thread.