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

  • 关于我们
  • 免责声明