我不明白为什么Java编译器给我“未选中转换”警告在以下情况:Java的泛型列表给我警告
我有这个类:
public class NodeTree<T> {
T value;
NodeTree parent;
List<NodeTree<T>> childs;
NodeTree(T value, NodeTree parent) {
this.value = value;
this.parent = parent;
this.childs = null;
}
public T getValue() { return value; }
public void setValue(T value) { this.value = value; }
public NodeTree getParent() { return parent; }
public void setParent(NodeTree parent) { this.parent = parent; }
public List<NodeTree<T>> getChilds() {
if (this.childs == null) {
this.childs = new LinkedList<NodeTree<T>>();
}
return this.childs;
}
}
,并在主类我有以下说明:
NodeTree node = new NodeTree<Integer>(10, null);
NodeTree<Integer> child = new NodeTree<Integer>(20, node);
List<NodeTree<Integer>> childs = node.getChilds();
childs.add(child);
我无法解释为什么我上getChilds()线这种类型的警告地狱:
个warning: [unchecked] unchecked conversion
List<NodeTree<Integer>> childs = node.getChilds();
^
required: List<NodeTree<Integer>>
found: List
1 warning
getChilds()函数不返回列表类型,则它返回列表< NodeTree < T>>类型。
请帮我理解。
在课程名称前写上'@SurpressWarning(“all”)' –