Closed Whojohn closed 3 years ago
错误页:
错误内容
- ArrayList 实现了 Cloneable 接口,支持
深拷贝
正确描述
- ArrayList 实现了 Cloneable 接口,默认为
浅拷贝
实例代码
ArrayList<List<Integer>> temp = new ArrayList<List<Integer>>() {{ add(new ArrayList<Integer>() {{ add(1); }}); add(new ArrayList<Integer>() {{ add(2); }}); add(new ArrayList<Integer>() {{ add(3); }}); }}; List<List<Integer>> temp2 = (List<List<Integer>>) temp.clone(); System.out.println("Copy source must be as follow when copy is deepcopy"); temp.forEach(System.out::println); temp.get(1).add(3); System.out.println("Copy source:"); temp2.forEach(System.out::println);
谢谢指正,你是对的
错误页:
错误内容
深拷贝
正确描述
浅拷贝
实例代码