Andrey Arzhannikov Andrey Arzhannikov - 4 months ago 43
Android Question

validateEagerly() method in Retrofit 2.0 (beta 2)

What exactly does

(Retrofit 2.0 beta 2) method do?
Where can I apply this method?

JavaDoc says that
When calling create on the resulting Retrofit instance, eagerly validate the configuration of all methods in the supplied interface.
but this description is not so clear.


validateEagerly() validates the configuration you have provided when building your Retrofit instance. This will inspect your interface annotations for valid Retrofit annotations, inspection of arguments and method arguments, if they are consistent with the annotations set, also this checks for possible incorrect method return types (different than Call<T>).

The inspection is usually called before you build your Retrofit instance.

private Retrofit getRetrofit() {
        OkHttpClient okClient = getOkHttpClient();
        GsonBuilder builder = getGsonBuilder();
        Retrofit.Builder retrofitBuilder = new Retrofit.Builder();

It can throw IllegalArgumentException with different message and cause, if something is not valid.