通过克隆基于现有对象创建对象(克隆羊)
当需要一个与现有对象类似的对象时,或者与克隆相比,创建的成本会很高。
示例:Arraylist的clone()123456789101112131415ArrayList<Student> listCopy=(ArrayList<Student>) list.clone();public Object clone() { try { @SuppressWarnings("unchecked") ArrayList<E> v = (ArrayList<E>) super.clone(); v.elementData = Arrays.copyOf(elementData, size); v.modCount = 0; return v; } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(); } }