ジェネリック クラスに static final 変数を持つことは設計上の欠陥ですか? 以下のクラスを検討してください。すべての参照でNode.SOIL
警告が発生します。この問題を解決するための良い方法は何ですか?
public class Node<E> {
private static int nodeCounter = 0;
@SuppressWarnings({ "unchecked", "rawtypes" })
public static final Node SOIL = new Node(null, null); // <-- HERE
public static void resetSOIL(){
SOIL.children = null; // <-- HERE
}
private Node<E> parent;
private Set<Node<E>> children;
protected Set<Node<E>> isomorphs;
private E data;
private int id;
public Node(Node<E> parent, E data){
this.parent = parent;
this.data = data;
this.id = ++nodeCounter;
}
public boolean isRoot(){
return (this.getParent() == SOIL);
}
// utility methods
....
}