Java - Warning: Unchecked cast from object to array list

时间:2015-02-08 00:28:12   收藏:0   阅读:462

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


技术分享


原文:http://blog.csdn.net/caroline_wendy/article/details/43614705

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!