Java - Warning: Unchecked cast from object to array list

来源:互联网 发布:单片机地址总线 编辑:程序博客网 时间:2024/05/01 14:47

Warning: Unchecked cast from object to array list


本文地址:http://blog.csdn.net/caroline_wendy


警告发生在对象(Object)强制转换为数组(ArrayList)类型,如:
infos = (ArrayList<VideoInfo>) data.getData();

因为对象转换为数组类型,未经过检查,有一定危险.
使数组对象强制转换,如ArrayList<?>,比较容易控制风险。

但是,为了书写简便和适配其他不规范接口,这么做是可以的。
可以在方法(method)前,进行警告抑制(SuppressWarning),即
@SuppressWarnings("unchecked”)

参考: http://stackoverflow.com/questions/509076/how-do-i-address-unchecked-cast-warnings




2 0
原创粉丝点击