Retrofit을 사람들은 어떻게 사용하는지 공부하고 있는데 처음부터 막혀서 질문드립니다.
public static RetrofitAPI getApiService(){
return getInstance().create(RetrofitAPI.class);
}
RetrofitAPI라는 인터페이스는 만들지는 않았지만 있다고 가정 하에 질문하겠습니다.
RetrofitAPI getApiService()의 뜻이
인터페이스 RetrofitAPI에 getApiService 메소드를 생성하고 getApiService메소드는 리턴 값으로 RetrofitAPI의 인스턴스를 생성하고 생성한 인스턴스의 객체를 리턴한다는건가요 ?...
getter와 setter의 개념이 들어간거 같긴한대.. getInstance().create()에서 create가 왜 나온건지 모르겠네요 ..
전체 코드는 아래와 같습니다.
package com.example.myapplication;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static final String BASE_URL = "http://sinwongyoon.ivyro.net/";
public static RetrofitAPI getApiService(){
return getInstance().create(RetrofitAPI.class);
}
private static Retrofit getInstance(){
Gson gson = new GsonBuilder().setLenient().create();
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
}