May I ask why this smart cast does not work? Thank...
# getting-started
n
May I ask why this smart cast does not work? Thanks.
Copy code
fun <T : Any> isNotNull(value: T?): Boolean {
    contract {
        returns(true) implies (value != null)
        returns(false) implies (value == null)
    }
    return value != null
}


class ContractTest {
    @Test
    fun test1() {
        val a: String? = null
        if (isNotNull(a)) {
            println(a.uppercase()) // Works as expected: "Smart cast to kotlin.String"
        }

        val notNull = isNotNull(a)
        if (notNull) {
            println(a.uppercase()) // Compilation error: "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?"
        }
    }
}
e