如何创建对象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();
}
//...
}