Which of the following is a correct way to create an instance of a Retrofit API interface?

4 phương ánCó giải thích

Các phương án trả lời

Chọn một phương án
Lời giảiChọn phương án để mở

Để tạo một instance của một interface Retrofit API, bạn cần sử dụng một cách cụ thể. Đầu tiên, bạn cần tạo một đối tượng Retrofit Builder bằng cách sử dụng phương thức new. Sau đó, bạn cần thêm baseUrl và converter factory vào đối tượng này. Cuối cùng, bạn có thể tạo instance của interface Retrofit API bằng phương thức create(). Ví dụ, bạn có thể sử dụng đoạn mã sau: Retrofit retrofit =

Lời giải
new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();

MyApiEndpointInterface api =

Lời giải
retrofit.create(MyApiEndpointInterface.class);

Cùng chương 8