如何创建对象的独立副本route
?问题是所有应用于的更新route_copy
也应用于route
. 如何避免这种情况?
public class Route implements Cloneable, Comparable<Route> {
//...
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
//...
}
public void processData(Route route)
{
route_copy = null;
try {
route_copy = (Route) route.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
//...
}