利用流来clone对象
现在需要clone的对象是HashMap needCloneMap,要将其clone为cloneMap.
操作如下:
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objectout = new ObjectOutputStream(out);
objectout.writeObject(needCloneMap);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ObjectInputStream objectin = new ObjectInputStream(in);
HashMap cloneMap = (HashMap) objectin.readObject();
克隆完毕。
[@more@]