Android 类型不匹配。必填项:suspend()→;回应<*&燃气轮机;发现:响应<;无效>;
在我的android应用程序中,这两种方法Android 类型不匹配。必填项:suspend()→;回应<*&燃气轮机;发现:响应<;无效>;,android,kotlin,kotlin-coroutines,Android,Kotlin,Kotlin Coroutines,在我的android应用程序中,这两种方法 GetTraiderList和executeTraderOperation必须返回类型TransportResponse 片段: interface TraderMonitorRestClient { @GET("traders/json") suspend fun getTraidersList(): Response<List<Trader>> @GET("trader/{trader_opera
GetTraiderList
和executeTraderOperation
必须返回类型TransportResponse
片段:
interface TraderMonitorRestClient {
@GET("traders/json")
suspend fun getTraidersList(): Response<List<Trader>>
@GET("trader/{trader_operation}")
suspend fun executeTraderOperation(@Path("trader_operation") traderOperation: String,
@Query("base") base: String,
@Query("quote") quote: String,
@Query("sender") sender: String,
@Query("key") key: String): Response<Void>
}
suspend fun getTraidersList(): TransportResponse = withContext(Dispatchers.IO) {
val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
executeOperation(traderMonitorRestClient.getTraidersList())
}
suspend fun executeTraderOperation(traderOperation: Trader.Operation, base: String, quote: String): TransportResponse = withContext(Dispatchers.IO) {
val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
val sender = BuildConfig.APPLICATION_ID + "_" + BuildConfig.VERSION_NAME
val key = DateUtil.getDateAsString(Date(), "mmHHddMMyyyy")
executeOperation(traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key))
}
suspend private fun executeOperation(someFunction: suspend () -> Response<*>): TransportResponse {
try {
val response: Response<*> = someFunction()
return onResponse(response)
} catch (e: Throwable) {
return onNetworkFailure(e)
}
}
错误消息:
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<List<Trader>>
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<Void>
错误消息:
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<List<Trader>>
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<Void>
类型不匹配。
必修的:
暂停()→ 回答
发现:
回答
使用
executeOperation {traderMonitorRestClient.getTraidersList() }