改造 2.6。
@GET("/event")
suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Event>>
在役:
import retrofit2.Response
suspend fun getEvents(
orgn: Int,
event: Int,
isCustomtHandle: Boolean = false
): Response<*> {
return waitressCallRestClient.getEvents(orgn, event)
}
在我的 ViewModel 中:
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
viewModelScope.launch(Dispatchers.Main) {
val response = TransportService.getEvents(100, 200)
if (response.isSuccessful) {
val eventList: List<Event> = response.body() as List<Event>
如您所见,我必须转换为List<Event>
是否可以避免手动转换?