その時に書きたいものを書きます

その時に書きたいものを書くんです

shallow copyについて

class Hoge implements Cloneable{
    public int intHoge = 0;
    public String[] arrHoge = new String[];
    public Hoge createClone(){
        Hoge hoge = null;
        try {
            hoge = (Hoge)clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return hoge;
    }
}

Hoge hoge = new Hoge();
Hoge fuga = hoge.createClone();

みたいなことをしたときにHoge型のオブジェクトは2個になるが、その中で定義されている配列arrHogeは1個しか存在しないことになる。それがshallow copy