Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Kotlin类型干扰失败_Android_Kotlin_Retrofit2 - Fatal编程技术网

Android Kotlin类型干扰失败

Android Kotlin类型干扰失败,android,kotlin,retrofit2,Android,Kotlin,Retrofit2,我在这里得到了这个错误: 类型推断失败:fun flatMap(p0:((响应)->SingleSource!)!:Single不能应用于((响应)->KFunction1) 我不知道为什么 以下是我的代码,错误是: 下面是我的ParseResendotResponse: flatMap函数将函数引用作为第一个参数this::ParseResendotResponse是一个函数引用,因此必须在括号中传递它 当您想要立即传递函数体时,我们使用大括号 list.flatMap({it.items}

我在这里得到了这个错误:

类型推断失败:fun flatMap(p0:((响应)->SingleSource!)!:Single不能应用于((响应)->KFunction1)

我不知道为什么

以下是我的代码,错误是:

下面是我的ParseResendotResponse:


flatMap
函数将函数引用作为第一个参数
this::ParseResendotResponse
是一个函数引用,因此必须在括号中传递它

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

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)
list.flatMap({it.items})//括号内的lambda
list.flatMap(){it.items}//括号外的lambda
list.flatMap{it.items}//lambda不带括号
val fn:(List)->List={it.items}//lambda
列表.平面图(fn)

所有这些表示相同的调用

Do
flatMap(this::parseResendotResponse)
。括号表示lambda,表示需要函数引用。您正在将函数包装到另一个函数中。使用括号而不是大括号。由于您的函数位于lambda内部,
这是指lambda接收器。这解决了问题,非常感谢。是的@sidgate,谢谢