Why == generates compilation error on different types in Kotlin
The following code cannot be compiled:
if ("2" == 3) {
//do something
}
Error: Kotlin: Operator '==' cannot be applied to 'String' and 'Int'
However, Kotlin reports that this is structural equality and is translated to a?.equals(b) ?: (b === null)
: https://kotlinlang.org/docs/reference/equality.html .
So what's going on here? How it works?
+3
source to share