I am puzzeled by the fact that the following snipp...
# compiler
u
I am puzzeled by the fact that the following snippet compiles:
Copy code
val x : (()->Unit)? = null


fun main() {
    if (x != null) {
        x.invoke()
    }
}
while with this one the compiler complains about the reference having a nullable type:
Copy code
val x : (()->Unit)? = null


fun main() {
    if (x != null) {
        x()
    }
}
Compiler and Android Studio even agree on complaining about the second snippet. Am I missing something?
j
Why wouldn't it compile? Second snippet looks like https://youtrack.jetbrains.com/issue/KT-4113
w
for me both compile without warning, AS 3.6 canary 9 and Kotlin 1.3.50
u
That's it @jw. Thanks