Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final XStream XSTREAM = new XStream();
- ...
- Object newObject = XSTREAM.fromXML(XSTREAM.toXML(obj));
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(object);
- oos.flush();
- oos.close();
- bos.close();
- byte [] byteData = bos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(byteData);
- (Object) object = (Object) new ObjectInputStream(bais).readObject();
- if (instance1 == instance2) {
- // same instance
- }
- if (instance1.equals(instance2)) {
- // same value. maybe or maybe not same instance.
- }
- import com.thoughtworks.xstream.XStream;
- public class deepCopy {
- private static XStream xstream = new XStream();
- //serialize with Xstream them deserialize ...
- public static Object deepCopy(Object obj){
- return xstream.fromXML(xstream.toXML(obj));
- }
- }
Add Comment
Please, Sign In to add comment