我与树的在Java中工作,我有一个简单的无序树下面的接口与自我参考:如何避免参数类型警告自引用java中的类型安全接口?
public interface Node<N extends Node> {
public N getParent();
public void setParent(N parent);
public Collection<N> getChildren();
public void addChild(N node);
public void removeChild(N node);
public N getRootNode();
... more ...
}
课程的想法是创建一个类型安全的节点
public abstract class ParentChildNode<E extends Node> implements Node<E> {
问题这真的让我很烦,被警告,我得到:
ParentChild is a raw type. References to generic type Node<N> should be parameterized
warning on this line:
public interface Node<N extends Node> {
warning on this line:
public abstract class ParentChildNode<E extends ParentChild> implements ParentChild<E>
我可以这样做:
public interface Node<N extends Node<?>> {
但我担心im踩到yuckness领土。我可以压制警告,但那不允许我在哪里工作。
有什么建议吗?我注意到java.util集合API在任何地方都没有任何警告。
在此先感谢