📜  如何在java代码示例中复制对象

📅  最后修改于: 2022-03-11 14:52:31.911000             🧑  作者: Mango

代码示例1
Example example = new Example(1, 2, "Example");
Example copiedExample = new Example(example);

class Example {
      
      public int a;
      public int b;
      public String c;
      
    // Constructor
    public Example(int a, int b, String s) {
      // ...
    }
  
      // Copy Constructor
      public Example(Example example) {
        this.a = example.a;
          this.b = example.b;
          this.s = example.s;
    }
}