java深拷贝和浅拷贝的区别
浅拷贝:只复制一个对象,对象内部存在的指向其他对象数组或者引用则不复制
深拷贝:对象,对象内部的引用均复制
示例:
public?static?Object?copy(Object?oldObj)?{Object?obj?=?null;
try?{
//?Write?the?object?out?to?a?byte?array
ByteArrayOutputStream?bos?=?new?ByteArrayOutputStream();
ObjectOutputStream?out?=?new?ObjectOutputStream(bos);
out.writeObject(oldObj);
out.flush();
out.close();
//?Retrieve?an?input?stream?from?the?byte?array?and?read
//?a?copy?of?the?object?back?in.
ByteArrayInputStream?bis?=?new?ByteArrayInputStream(bos.toByteArray());?
ObjectInputStream?in?=?new?ObjectInputStream(bis);
obj?=?in.readObject();
}?catch?(IOException?e)?{
e.printStackTrace();
}?catch?(ClassNotFoundException?cnfe)?{
cnfe.printStackTrace();
}
return?obj;
}
1、临摹 reproduction[,ri:pr?'d?k?n](copy['k?pi] );
1) copy that is not the original; something that has been copied(非原作复制,一些被复制)
2) the act of making copies (复制的行为)
2、浓淡法 gradation [ɡr?'dei?n]
1)n.relative position in a graded seriessubtle gradations in color (在一个分级的训练强度反应相对位置系列微妙颜色层次)
2.) a degree of ablaut(某种程度的微妙颜色元素的交替交换)
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!