In my android app:
app/build.gradle
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation "com.squareup.retrofit2:converter-gson:2.6.0"
implementation "com.squareup.retrofit2:retrofit:2.6.0"
In my interface:
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
interface MyRestClient {
@GET("/event")
suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Event>>
}
And I want to call this method synchronously.
So I try this:
import retrofit2.Call
import retrofit2.Response
class TransportService {
companion object {
private val myRestClient =
RestClientFactory.createRestClient(MyRestClient ::class.java)
suspend fun getEventSync(orgn: Int, event: Int): Response<*> {
val call: Call<*> = myRestClient .getEvents(orgn, event)
return call.execute()
}
And call by this:
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
viewModelScope.launch(Dispatchers.Main) {
val response = TransportService.getEvents(100, 200)
But I get compile error in this line:
val call: Call<*> = myRestClient.getEvents(orgn, event)
error is:
Type mismatch: inferred type is Response<List<Event>> but Call<*> was expected