I have a nullable string variable ab
. If I call toUpperCase
via safe call operator after I assign null to it, kotlin gives error.
fun m
I'm not sure but that seems to be a bug due to smart casting (to Nothing?
, subtype of every nullable type). This one works:
fun main(args: Array) {
var ab: String? = "hello"
ab = makeNull()
println(ab?.toUpperCase())
}
fun makeNull(): String? = null
The only difference: The compiler does not know the null
assignment directly, which seems to cause the error in your example. But still, yours should probably work too.