简体   繁体   English

类型不匹配。 必需: suspend () → Response&lt;*&gt; 找到:Response<Void>

[英]Type mismatch. Required: suspend () → Response<*> Found: Response<Void>

In my android app the two methods getTraidersList and executeTraderOperation must return type TransportResponse在我的 android 应用程序中,两个方法getTraidersListexecuteTraderOperation必须返回类型TransportResponse

Snippet:片段:

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

But I get compile errors in this lines:但是我在这一行中遇到编译错误:

executeOperation(traderMonitorRestClient.getTraidersList())

error message:错误信息:

Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<List<Trader>>

and here和这里

executeOperation(traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key))

error message:错误信息:

Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<Void>

executeOperation {traderMonitorRestClient.getTraidersList() }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型不匹配。 必需:结果<newsresponse> : 发现: 结果<response<newsresponse> &gt;? </response<newsresponse></newsresponse> - Type mismatch. Required: Result<NewsResponse>! Found: Result<Response<NewsResponse>>? 类型不匹配。 必需:片段,找到:PlaceAutocompleteFragment - Type mismatch. Required: Fragment, Found: PlaceAutocompleteFragment 类型不匹配。 要求:观察员<in Int!>成立:? - Type mismatch. Required: Observer<in Int!> Found:? 类型不匹配。 必需:找不到:回调&lt;*&gt; - Type mismatch. Required: Nothing Found: Callback<*> 类型不匹配。 必需:找到的上下文:在片段中 - Type mismatch. Required: Context Found: In Fragment 类型不匹配。 必需:ContentResolver! 找到:整数 - Type mismatch. Required: ContentResolver! Found: Int 类型不匹配。 必需:数组 <Uri> ! 找到:数组 <Uri?> - Type mismatch. Required: Array<Uri>! Found: Array<Uri?> 类型不匹配。 必需:字符串:找到:Int 错误 - Type mismatch. Required: String! Found: Int error 类型不匹配。 必需:FirebaseRecyclerAdapter<chatobject, chatvoiceviewholders> ? 成立:</chatobject,> - Type mismatch. Required: FirebaseRecyclerAdapter<ChatObject, ChatVoiceViewHolders>? Found: 类型不匹配。 所需上下文:找到 MyAdapter.ViewHolder - Type mismatch. Required Context: Found MyAdapter.ViewHolder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM