java中使用clone()来克隆对象时,直接调用就可以:
ReviewCost reviewCost = null;
try {
reviewCost = (ReviewCost) that.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
但是这样在运行中会有错误:
java.lang.CloneNotSupportedException: class com.bjhab.entity.ReviewCost
at com.zeroturnaround.jrebelbase.d.clone(SourceFile:261)
at com.bjhab.entity.ReviewCost.equals(ReviewCost.java:268)
原因是 that 对象需要实现Cloneable接口