我已经定义了一个子类,并希望有两个具有不同参数的构造函数。看起来像这样
public class GraphNode extends Entity{
protected String id;
public GraphNode(PVector pos, String id) {
super(pos,0);
this.id = id;
}
public GraphNode(PVector pos, String id, List<GraphEdge>) {
this(pos, id);
//do something else
}
}
编译器一直告诉我:
类型中的重复方法GraphNode(PVector,String) GraphNode
我做错了什么?
答案 0 :(得分:1)
应该是这样的
public class GraphNode extends Entity{
protected String id;
public GraphNode(PVector pos, String id) {
super(pos,0);
this.id = id;
}
public GraphNode(PVector pos, String id, List<GraphEdge> list) {
this(pos, id);
//do something else
}
}
答案 1 :(得分:1)
你忘了给你的第三个参数一个变量名:
public GraphNode(PVector pos, String id, List<GraphEdge> list)