Kotlin型干扰失败

问题描述 投票:1回答:1

我这里出现了这个错误。

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>>)

我不知道为什么

这是我的代码,错误就在这里。

enter image description here

这里是我的parseResendOtpResponse:

enter image description here

android kotlin retrofit2
1个回答
1
投票

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)

以上都代表了相同的调用

© www.soinside.com 2019 - 2024. All rights reserved.