以下代码片段会抛出错误:"Generic array creation",尽管Node类中没有任何泛型实例。但是,如果我将私有类Node声明为静态的,则错误消失了。为什么在这里使用static关键字很重要?
public class SeperateChainingST<Key, Value>{
private int M =97;
private Node[] st = new Node[M];
private class Node{
Object key;
Object val;
Node next;
}
}
private SeperateChainingST.Node[] st = new SeperateChainingST.Node[M];
但是使用原始类型是不被鼓励的。相反,你应该使用集合,如private List<SeperateChainingST<Key, Value>.Node> list = new ArrayList<>();
。 - Pshemo