使用簡單粗暴的方式實現(xiàn)類復制
新建一個測試類供鸠,繼承Cloneable接口
public static class A implements Cloneable {
public Object clone() {
A o = null;
try {
o = (A) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
測試一下
public static void main(String[] args) {
A a = new A();
System.out.println(a);
System.out.println(a.clone());
}
測試結(jié)果
com.xxx.test.A@70177ecd
com.xxx.test.A@1e80bfe8