无论出于何种原因,当我尝试为植物数组列表创建深层副本时,我得到一个空指针异常,我不知道为什么。
/**
* Copy Constructor. Since landscape is immutable in the scope of our
* project, you could do a simple reference copy for it. However, Fish and
* Plants are mutable, so those lists must be copied with a DEEP copy! (In
* other words, each fish and each plant must be copied.)
*/
private ArrayList<Fish> fish;
private ArrayList<Plant> plants;
private int[][] landscape;
public Model(Model other) {
this.landscape = other.landscape;
for(Fish fishy: other.fish){
this.fish.add(new Fish(fishy));
}
for(Plant planty: other.plants){
this.plants.add(new Plant(planty));
}
}