1
我Graph<T>
类有Node<T>
(内部)类:泛型方法不适用于参数
public class Graph<T> {
private ArrayList<Node<T>> vertices;
public boolean addVertex(Node<T> n) {
this.vertices.add(n);
return true;
}
private class Node<T> {...}
}
当我运行此:
Graph<Integer> g = new Graph<Integer>();
Node<Integer> n0 = new Node<>(0);
g.addVertex(n0);
最后一行给我的错误:
The method addVertice(Graph<Integer>.Node<Integer>) in the type Graph<Integer> is not applicable for the arguments (Graph<T>.Node<Integer>)
为什么?提前致谢?
什么语言?我在猜测C#,但可能有其他人使用相同(或类似)的语法。 –
你在哪里定义了addVertice?我们在例子中看不到它。 –
您应该使'Node'类为'static'。 – 2012-10-01 04:49:14