I implemented the copy constructor as it is described here. But still the problem is that when I update route_copy
, then the same update is applied to route
. So, I don't understand what is wrong in my code?
public class Route implements Comparable<Route> {
private List<Site> sites;
public Route()
{
sites = new ArrayList<Site>();
}
public Route(List<Site> sites)
{
this.sites = sites;
}
/**
* Copy constructor
*/
public Route(Route r) {
this(r.sites);
}
public void deleteSite(Site s) {
this.sites.remove(s);
}
}
public processData(Route route)
{
Route route_copy = new Route(route);
Site s = selectSite(route_copy);
route_copy.deleteSite(s); // !!! now 'route' does not contain an element 's'
}