Java Object Deep Clone deepClone(Object src)

Here you can find the source of deepClone(Object src)

Description

deep Clone

License

Open Source License

Declaration

public static Object deepClone(Object src) 

Method Source Code


//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {

    public static Object deepClone(Object src) {
        try {/*w w w.j  ava 2  s .  co  m*/
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(src);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            return ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. deepClone(final E object)
  2. deepClone(final T objectToBeClonned)
  3. deepClone(Object obj)
  4. deepClone(Object objToClone)
  5. deepClone(Object src)
  6. deepClone(Serializable o)
  7. deepClone(Serializable serializable)
  8. deepClone(T toClone, final ClassLoader classLoader)