В моем приложении для Android два метода getTraidersList
и 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)
}
}
Но я получаю ошибки компиляции в следующих строках:
executeOperation(traderMonitorRestClient.getTraidersList())
сообщение об ошибке:
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<List<Trader>>
и здесь
executeOperation(traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key))
сообщение об ошибке:
Type mismatch.
Required:
suspend () → Response<*>
Found:
Response<Void>