Consider the following code:
Example
fun main(args: Array<String>) {
maybeWriteMessage()
}
fun maybeWriteMessage(message: String? = null) {
writeMessage(message!!)
}
fun writeMessage(message: String) {
println("Hello World")
}
Output个
线程"main"kotlin中出现异常.KotlinNullPointerException在
This is because I'm passing message!!
(null, damn it!) to a non-nullable parameter, however the parameter is never accessed.
Question
Why does Kotlin forcibly throw KotlinNullPointerException
even when the null reference isn't accessed?