简体   繁体   English

未选中调用方法作为原始类型的成员

[英]Unchecked call to method as a member of raw type

Following warning is shown in my project - 以下警告显示在我的项目中 -

Unchecked call to 'getWeatherData(T,Boolean,String)' as a member of raw type 'IWeatherCallbackListener'. 未选中调用'getWeatherData(T,Boolean,String)'作为原始类型'IWeatherCallbackListener'的成员。

I have created following interface - 我创建了以下界面 -

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

And called it in following way, 并按以下方式调用它,

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 have implemented this interface in my MainActivity and called the method as - 我在我的MainActivity中实现了这个接口,并将该方法称为 -

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

Can anyone please help and explain this warning. 任何人都可以帮助并解释这个警告。

Looks like you have to declare your T type too, in your case it has to be a class of response.body() instance. 看起来你必须声明你的T类型,在你的情况下它必须是一个response.body()实例类。

Try to replace line 尝试更换线路

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

to

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

That is so because when you declare your interface 这是因为当你声明你的界面时

IWeatherCallbackListener<T>

You use T and its raw type. 您使用T及其原始类型。 When you create instance you have to show what exactly type you will use or what exactly type you want to receive as argument. 当你创建的实例你必须表明, 究竟是什么类型,你会使用或究竟键入您希望收到作为参数。

For example if you create that listener manually that had to look like this 例如,如果您手动创建该侦听器,则必须如下所示

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

Same thing for arguments, you have to show what T you can receive. 对于论点同样的事情,你要显示什么T ,你可以收到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未经检查的调用原始类型的成员 - unchecked call to member of raw type 以原始类型的成员形式对…的未选中的调用 - unchecked call to … as a member of a raw type 未经检查地调用“continueWithTask…”作为原始类型的成员 - Unchecked call to 'continueWithTask…' as a member of raw type 如何正确地调用具有泛型类型的参数的方法并摆脱“未经检查的原始类型成员的调用”警告 - How to correctly call a method with parameter of generic type and get rid of the “unchecked call to member of raw type” warning unchecked调用setClass(Class <T> )作为原始类型的成员 - unchecked call to setClass(Class<T>)as a member of the raw type 未经检查地调用 add(E) 作为原始类型 ArrayList 和 HashMap 的成员 - unchecked call to add(E) as a member of the raw type ArrayList and HashMap 编译警告:未选中调用XXX作为原始类型的成员 - Compilation warning: Unchecked call to XXX as member of the raw type 未经检查的调用push(E)作为原始类型Stack的成员 - unchecked call to push(E) as a member of the raw type Stack 原始类型为“ java.lang.Iterable”的成员对“ forEach()”的未经检查的调用 - Unchecked call to 'forEach()' as a member of raw type 'java.lang.Iterable' 未选中的对commitList(List的调用 <T> )作为原始类型ListAdapter的成员 - Unchecked call to submitList(List<T>) as a member of the raw type ListAdapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM