public static Object clone(Object obj)
throws ResourceBusyException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oout;
try {
oout = new ObjectOutputStream(out);
oout.writeObject(obj);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
return in.readObject();
} catch (Exception e) {
throw new ResourceBusyException();
}
}
经过简单测试,理论上可以做到直接克隆Java的任何对象,但不保证代码的可靠性。