1. 效率高
@Override public Person clone () throws CloneNotSupportedException { return (Person)super.clone(); }
2. 效率低
@Override public Person clone () throws CloneNotSupportedException { Person person = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject( this ); oos.close(); } catch (IOException e) { e.printStackTrace(); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); try { ObjectInputStream ois = new ObjectInputStream(bais); person = (Person) ois.readObject(); ois.close(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return person; }