2013-07-17 158 views
0

如何創建對象的獨立副本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(); 
     } 
//... 
} 

回答

相關問題