您的位置:首页 > 移动开发 > Objective-C

Java 警告------Type safety: The method add(Object) belongs to the raw type Vector

2015-07-30 21:10 483 查看
rowdata.add(hang);

// Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector<E> should be parameterized

// 为什么会报这个警告???

Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector<E> should be parameterized

翻译:类型安全:该方法添加(对象)属于原始类型向量。对泛型类型向量的引用要进行参数化

分析;

这是因为JDK 1.5版本的新功能,需要对List,Vector之类定义时候,最好进行泛化。

定义类型,如:Vector<String> v = new Vector<String>();

这样的好处是再你add("abc");后想获取这个元素不需要再转化了。

如,v.get(0)将返回的就是一个String对象。

显示类型转换:

Vector <String > v=new Vector<String>();

即可,解决问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: