The copy constructor creates dependent copy

前端 未结 5 1164
盖世英雄少女心
盖世英雄少女心 2021-01-23 16:34

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

5条回答
  •  没有蜡笔的小新
    2021-01-23 17:19

    Your "copy constructor" is not making a copy of the input list. Try something like

    public Route(List sites)
    {
        this.sites = new ArrayList(sites);
    }
    

    for your second constructor.

提交回复
热议问题