在我的 Android 项目中,我创建了一个抽象的 AsyncTask 类,我在其中输入 URL 以及如果需要分页信息,因此我不需要继续编写 HTTP 内容等。
我制作了一个抽象方法 onAsyncTaskResult(Object o) 必须在使用时实现。但是,当将其转换为适当的对象(可以是不同类型)时,IDE 会给我一个警告
"Unchecked cast for java.lang.Object to java.util.ArrayList<com.company.package.subpackage.MyItem>"
这是我实现所述功能的代码片段
new SuperCoolAsyncTask() {
@Override
protected void onAsyncTaskResult(Object o) {
if(o instanceof ArrayList) {
//generates warning in the following line
AppConstants.scoreStatistics = (ArrayList<MyItem>)o;
}
}
}.execute(get_url_score_statistics());
我应该如何在ArrayList<MyItem>
不产生警告的情况下将其转换为?
没有<MyItem>
声明,它会引发“未经检查的分配”