当前页面: 开发资料首页 → J2SE 专题 → 为什么我这样的代码会有这样的警告
为什么我这样的代码会有这样的警告
摘要: 为什么我这样的代码会有这样的警告
Vector judge = new Vector();
judge.addElement("abc");
Type safety: The method addElement(Object) belongs to the raw type Vector. References to
generic type Vector
should be parameterized
add(Object o)将对象O添加到向量的末尾
或者用addElements(Object o)
JDK 1.5版本的新功能,需要对List,Vector之类定义时候,可以进行泛化。
定义类型,如:Vector v = new Vector();
这样的好处是再你add("abc");后想获取这个元素不需要再转化了。
如,v.get(0)将返回的就是一个String对象。方便!
范型
楼上所言极是
原来如此,明白了,谢谢