Junior — Middle
What type of data does a method of an interface implementing HTTP requests through Retrofit return?
sobes.tech AI
Answer from AI
The interface method that implements HTTP requests through Retrofit usually returns an object of type Call<T>, where T is the expected response type.
For example:
public interface ApiService {
@GET("users/{id}")
Call<User> getUser(@Path("id") int userId);
}
Here, the getUser method returns Call<User>. This object allows you to perform the HTTP request asynchronously or synchronously and receive a response that will be deserialized into a User object.
In newer versions of Retrofit, you can also use Deferred<T> for integration with Kotlin Coroutines or Observable<T> for RxJava, but the basic type remains Call<T>.