新版本的变更 / Kotlin 1.7

// a Java interface:
// public interface Store<T> { T save(T value); }

// *** before: ***
// when overriding a Java generic there was no way to say
// "T is never null here", so the platform type leaked through
fun <TorDefaultOld(value: T?, defT): T = value ?: def

// *** in version 1.7: ***
fun <TorDefault(value: T?, defT & Any): T & Any = value ?: def

class Box<T> {
    private var stored: T? = null

    fun put(value: T & Any) {   // not nullable even if T itself is
        stored = value
    }
}

fun main() {
    println(orDefault(null"fallback"))
    Box<String?>().put("value")
    // Box<String?>().put(null)   // <- Error, which is the whole point
}