Skip to content

Commit 31ad98d

Browse files
committed
深拷贝总结
1 parent d634b66 commit 31ad98d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

Basics/src/com/copy/Student.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ protected Object clone() throws CloneNotSupportedException {
5050
// 深拷贝
5151
Student student = new Student(new Subject(subject.getName()), name);
5252
return student;
53+
// 因为它是深拷贝,所以你需要创建拷贝类的一个对象。
54+
// 因为在Student类中有对象引用,所以需要在Student类中实现Cloneable接口并且重写clone方法。
5355
}
5456
}

0 commit comments

Comments
 (0)