kotlin中泛型的为空问题


fun <T>testA(): T? {
    return null
}
//编译成功

fun <T>testB(): T {
    return null
}
//上述代码报错,Null can not be a value of a non-null type T
//即一个不可空的变量(泛型)不能接受一个null

那么,问题来了,如果我们书写一个lambda表达式,此时我们可以返回空值并且编译不报错,这正是我查看let等拓展函数时产生的疑问

fun <T, R> T.myTest(block: (T) -> R): R {
    return block(this)
}
fun main() {
    val a = 1
    println(a.myTest { null })
}
//成功打印结果
// null

那么,KT中的泛型究竟是否包含空?
或者是仅仅编译时检测