复制构造函数Java

时间:2017-03-24 02:30:18

标签: java constructor

我将一个名为Node的类定义为

private class Node {
      public Node father;
      public JigSaw js;
      public int dist;

      public Node(Node father, JigSaw js, int d){
        this.father = father;
        this.js  = js;
        this.dist = d;
      }
      public Node(Node aux){
        this(aux.father, aux.js, aux.dist);
      }
}

但是,当我做的时候

Node next_n = new Node(prev_n);

更改next_n内容,prev_n也会更改! 如何取消链接这些对象?

0 个答案:

没有答案