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>();
即可,解决问题
// 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>();
即可,解决问题
相关文章推荐
- List<Map<String,Object>>使用Java代码遍历以获取String,Object的值
- PB之入门-itemchanged(long row,dwobject dwo,string data)
- 黑马程序员——Objective-C介绍
- objective-c之基础
- PHP、JAVA、C#、Object-C 通用的DES加密
- C#中Object转化为json对象
- windows搭建Objective-c开发环境
- Object-C 中的可变数组和不可变数组
- vs2010中objectARX工程创建类
- Objective-C语言
- IOS开发系列—Objective-C之内存管理详解
- Object-C 可变字符串(NSMutableString)
- Windows API函数 WaitForMultiObjects 的使用注意事项
- Fatal error Using $this when not in object context in
- 问题解决:Unlink of file '.git/objects/pack/pack-***.pack' failed. Should I try again? (y/n) y
- Object对象详解(二)之clone
- 关于java中Object类的某些方法的总结
- Object对象详解(一)之toString
- extjs grid summary 获取平均分数据,并传递object后后台,存储得到想要的数据。
- Microservices and the First Law of Distributed Objects