[英]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.