次の状況で 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()関数は List タイプを返さず、List < NodeTree < T > > タイプを返します。
理解するのを手伝ってください。