Unverified method call as a member of type raw

My project shows the following warning -

An unverified call to 'getWeatherData (T, Boolean, String)' as a raw element of type 'IWeatherCallbackListener'.

I created the following interface -

public interface IWeatherCallbackListener<T> {
 void getWeatherData(T weatherModel, Boolean success, String errorMsg);
}

And he called it as follows:

public class WeatherConditions {

private static IWeatherApi mWeatherApi;

/**
 * @param city
 * @param appId
 * @param listener
 */
public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener listener) {

    mWeatherApi = ApiService.getRetrofitInstance(BASE_URL_OPEN_WEATHER).create(IWeatherApi.class);
    Call<OpenWeatherModel> resForgotPasswordCall = mWeatherApi.getOpenWeatherData(appId, city);
    resForgotPasswordCall.enqueue(new Callback<OpenWeatherModel>() {
        @Override
        public void onResponse(Call<OpenWeatherModel> call, Response<OpenWeatherModel> response) {
            if (response.body() != null) {
                if (listener != null)
                    listener.getWeatherData(response.body(), true, "");
            }
        }

        @Override
        public void onFailure(Call<OpenWeatherModel> call, Throwable t) {
            if (listener != null)
                 listener.getWeatherData(null, false, t.getMessage());
        }
    });
}

I implemented this interface in my MainActivity and named the as method -

WeatherConditions.getOpenWeatherData(etCityName.getText().toString(), OPEN_WEATHER_APP_ID, MainActivity.this)

Someone can help and explain this warning.

+4
source share
1 answer

It looks like you need to declare your type T, in your case it should be an instance class response.body().

Try replacing the string

public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener listener)

to

public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener<ResponseBody> listener)

This is because when you declare your interface

IWeatherCallbackListener<T>

T . , , , , .

, ,

IWeatherCallbackListener<ResponseBody> listener = new IWeatherCallbackListener<ResponseBody>() {
    //implementation of methods
}

, , T .

+5

Source: https://habr.com/ru/post/1688507/


All Articles