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>) {
       this(pos, id);
       //do something else
   }
}

编译器一直告诉我:

GraphNode 类型中的重复方法 GraphNode(PVector, String)

我究竟做错了什么?

4

2 回答 2

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
   }
}
于 2012-05-10T18:07:51.487 回答
1

你忘了给你的第三个参数一个变量名:

public GraphNode(PVector pos, String id, List<GraphEdge> list)
于 2012-05-10T18:08:35.107 回答