Java克隆

通过搜索了解到,克隆大概有两个作用

1.为了安全,希望对新对象的操作,不对原对象有影响

例如:

class Test {
    private static int[] value;
    static {
        value = new int[]{1, 2, 3, 4, 5};
    }
    public static final int[] getValue() {
        return value.clone();
    }
}

为了不破坏value数组的值,使用value的克隆

2.当对象的创建比较复杂的时候,或者不知道对象是怎么创建出来的,那就用克隆吧

 

关于浅克隆和深克隆:

http://blog.csdn.net/hj7jay/article/details/51441225

posted @ 2017-02-17 12:09  叫我什么大人  阅读(161)  评论(0编辑  收藏  举报