62,621
社区成员
发帖
与我相关
我的任务
分享protected Object clone() throws CloneNotSupportedException {
Elem e new Elem();
e.children = new ArrayList<Elem>();
for (Elem child : this.children)
e.children.add(child.clone());
return e;
}
你的方法里,注意这两行:
e.children = new ArrayList<Elem>();
for(int i=0;i<e.children.size();i++){
e.children是一个新的ArrayList,所以下面这个循环没有效果