Alexei
Alexei

Reputation: 15674

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

In my android app the two methods getTraidersList and executeTraderOperation must return type 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>

Upvotes: 0

Views: 852

Answers (1)

r2rek
r2rek

Reputation: 2243

Use

executeOperation {traderMonitorRestClient.getTraidersList() }

Upvotes: 1

Related Questions