Kotlin 类型干扰失败

Kotlin type interference failed

我在这里遇到这个错误:

Type inference failed: fun <R : Any!> flatMap(p0: ((Response<ResendOtpResponseDto!>) -> SingleSource<out R!>!)!): Single<R!> cannot be applied to ((Response<ResendOtpResponseDto!>) -> KFunction1<@ParameterName Response<ResendOtpResponseDto>, Single<ResendOtpResponseDto>>)

不知道为什么。

这是我的错误代码:

这是我的 parseResendOtpResponse:

flatMap 函数将函数引用作为第一个参数。 this::parseResendOtpResponse 是一个函数引用,所以你必须在括号中传递它。

当你想立即传递函数体时,我们使用大括号。

list.flatMap({it.items}) // lambda within parentheses

list.flatMap(){it.items} // lambda outside parentheses 

list.flatMap {it.items} // lambda without parentheses

val fn: (List<List<...>>) -> List<...> = { it.items }  //lambda
list.flatMap(fn)

以上代表同一个调用