使用对象序列化进行克隆

xiaoxiao2022-12-01  183

摘自java核心技术

 

注意:效率较低

 

class SerialCloneable implements Cloneable, Serializable{ public Object clone() { try{ //save the object to a byte array ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(this); out.close(); //read a cline of the object from the byte array ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); Object ret = in.readObject(); in.close(); return ret; }catch (Exception e) { // TODO: handle exception return null; } } } 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-4979210.html

最新回复(0)