logo
  • 教程列表
  • SO官方文檔
  • 物件克隆
    • 克隆執行深層複製
    • 使用複製建構函式進行克隆
    • 通過實現 Clonable 介面進行克隆
    • 克隆執行淺拷貝
    • 使用複製工廠克隆
  1. StackOverflow 文件
  2. Java Language 教程
  3. 物件克隆
  4. 使用複製工廠克隆

使用複製工廠克隆

Created: November-22, 2018

public class Sheep {

    private String name;
    
    private int weight;
    
    public Sheep(String name, int weight) {
        this.name = name;
        this.weight = weight;
    }
    
    public static Sheep newInstance(Sheep other);
        return new Sheep(other.name, other.weight)
    }

}
  • 克隆執行淺拷貝

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明