The following code is rejected by the Kotlin compiler (rightfully so):
// main.kt
class KotlinFoo(val bar: java.lang.CharSequence)
fun test(foo: KotlinFoo) {
println(foo.bar == "hi")
}
Error:
Operator '==' cannot be applied to 'CharSequence' and 'String'
The following, however, is accepted without complaints:
// JavaFoo.java
public class JavaFoo {
public java.lang.CharSequence bar;
}
// main2.kt
fun test(foo: JavaFoo) {
println(foo.bar == "hi")
}
I would have expected it to generate the same error.
Is this compiler behavior intended?