-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathResume_deep.java
More file actions
97 lines (78 loc) · 1.92 KB
/
Resume_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
package u009;
/**
* Created by HuGuodong on 11/21/19.
*/
public class Resume_deep implements Cloneable, IResume{
private String name;
private int age;
// workExperience 为引用类型,浅拷贝只复制地址。
// 必须使用深拷贝
private WorkExperience workExperience;
public Resume_deep(){
this.workExperience = new WorkExperience();
}
public void setPersonalInfo(String name, int age){
this.name = name;
this.age = age;
}
public void setWorkExperience(String timeSpan, String company){
workExperience.setTimeSpan(timeSpan);
workExperience.setCompany(company);
}
@Override
public String toString() {
return "Resume_deep{" +
"name='" + name + '\'' +
", age=" + age +
", workExperience=" + workExperience +
'}';
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
public Object deepCopy(){
Resume_deep obj = null;
try{
obj = new Resume_deep();
obj.name = this.name;
obj.age = this.age;
obj.workExperience = (WorkExperience) this.workExperience.clone();
}catch (Exception e){
e.printStackTrace();
}
return obj;
}
public void print(){
System.out.println(toString());
}
}
class WorkExperience implements Cloneable{
private String timeSpan;
private String company;
public WorkExperience(){
}
public void setTimeSpan(String timeSpan) {
this.timeSpan = timeSpan;
}
public void setCompany(String company) {
this.company = company;
}
public String getTimeSpan() {
return timeSpan;
}
public String getCompany() {
return company;
}
@Override
public String toString() {
return "WorkExperience{" +
"timeSpan='" + timeSpan + '\'' +
", company='" + company + '\'' +
'}';
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}