Kotlin:具有可空 return 值的 BiFunction 无法编译

Kotlin: BiFunction with nullable return value fails to compile

这段(大大简化的)代码无法为我编译。不知道为什么。 return 类型是 Entry? 并且 null 对我来说似乎是一个有效值。

val foo = BiFunction<Int, List<Entry>, Entry?> { foo:Int, bar:List<Entry> ->
    null
}

错误信息是Null can not be a value of a non-null type Entry

谁能告诉我我错过了什么?

我正在使用:

ext.kotlin_version = '1.2.10'
compile "io.reactivex.rxjava2:rxjava:2.1.8"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

我欢迎任何建议。新年快乐!

BiFunction class 中的 apply 方法在其 return 值(及其参数)上有一个 @NonNull 注释。显然,您不能通过提供可空类型作为类型参数来覆盖它。

你可能也不应该:RxJava 2 流中不能有 null 元素(参见 here)。