- Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathResume_deep.java
More file actions
Latest commit
97 lines (78 loc) · 1.92 KB
/
Copy pathResume_deep.java
File metadata and controls
97 lines (78 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
packageu009;
/**
* Created by HuGuodong on 11/21/19.
*/
publicclassResume_deepimplementsCloneable, IResume{
privateStringname;
privateintage;
// workExperience 为引用类型,浅拷贝只复制地址。
// 必须使用深拷贝
privateWorkExperienceworkExperience;
publicResume_deep(){
this.workExperience = newWorkExperience();
}
publicvoidsetPersonalInfo(Stringname, intage){
this.name = name;
this.age = age;
}
publicvoidsetWorkExperience(StringtimeSpan, Stringcompany){
workExperience.setTimeSpan(timeSpan);
workExperience.setCompany(company);
}
@Override
publicStringtoString() {
return"Resume_deep{" +
"name='" + name + '\'' +
", age=" + age +
", workExperience=" + workExperience +
'}';
}
@Override
publicObjectclone() throwsCloneNotSupportedException {
returnsuper.clone();
}
publicObjectdeepCopy(){
Resume_deepobj = null;
try{
obj = newResume_deep();
obj.name = this.name;
obj.age = this.age;
obj.workExperience = (WorkExperience) this.workExperience.clone();
}catch (Exceptione){
e.printStackTrace();
}
returnobj;
}
publicvoidprint(){
System.out.println(toString());
}
}
classWorkExperienceimplementsCloneable{
privateStringtimeSpan;
privateStringcompany;
publicWorkExperience(){
}
publicvoidsetTimeSpan(StringtimeSpan) {
this.timeSpan = timeSpan;
}
publicvoidsetCompany(Stringcompany) {
this.company = company;
}
publicStringgetTimeSpan() {
returntimeSpan;
}
publicStringgetCompany() {
returncompany;
}
@Override
publicStringtoString() {
return"WorkExperience{" +
"timeSpan='" + timeSpan + '\'' +
", company='" + company + '\'' +
'}';
}
@Override
protectedObjectclone() throwsCloneNotSupportedException {
returnsuper.clone();
}
}