PHondogo
06/19/2025, 9:29 AMval x : Int? = 5
// x!! // if uncomment this line there will be no compilation error
x + 1 // compilation error as x treated as nullable. I think compiler can 'smart cast' it from initial assignmentdmitriy.novozhilov
06/19/2025, 9:39 AM= only in case of variable assignment, not the variable initialization.
fun main() {
val x : Int?
x = 5
x + 1 // smartcasted
}PHondogo
06/19/2025, 9:55 AM@Test
fun test() {
var x : Int? = 5
x!!
x + 1
x = null
val y = x + 1 // treat y as String // why?
println(y) // print null1
}dmitriy.novozhilov
06/19/2025, 9:56 AMx smartcasted to Nothing?
• + resolved to operator fun String?.plus(other: Any?): String from stdlibPHondogo
06/19/2025, 9:57 AMdmitriy.novozhilov
06/19/2025, 10:05 AMNothing? is subtype of String?