Type safety: The method add(Object) belongs to the raw type List. References to generic type List
should be parameterized
example
List treenode = new ArrayList
treenode.add(node);
javadoc 中List这样定义 Public interface List<E>
extends Collection,Iterable
注意这个<E>
,它就是JavaTiger的类型安全标志,到这里可以给出在保证类型安全时例子中的List应该如何定义了: List<TreeNode> treenode = new ArrayList<TreeNode>(); TreeNode为自定义类型,当然可以其它类型了,不过统一使用一种类型就是安全的了,不会有这个警告。
同理,map不加<>也会出现类似的警告
Map<String,Integer> h=new HashMap<String,Integer>();