FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaCodeAcc/src/designpattern/prototype/PrototypeClient.java at master · kylez7/JavaCodeAcc · GitHub
kylez7
/
JavaCodeAcc
Public
forked from
echoTheLiar/JavaCodeAcc
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaCodeAcc
/
src
/
designpattern
/
prototype
/
PrototypeClient.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (46 loc) · 1.56 KB
Breadcrumbs
JavaCodeAcc
/
src
/
designpattern
/
prototype
/
PrototypeClient.java
Copy path
File metadata and controls
62 lines (46 loc) · 1.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
designpattern
.
prototype
;
import
java
.
io
.
IOException
;
/**
* 原型模式客户端 演示深度拷贝和浅度拷贝
*
* @Todo 考虑优化此处的重复代码
* @author liu yuning
*
*/
public
class
PrototypeClient
{
public
static
void
shallowCopy
()
throws
CloneNotSupportedException
{
Resume
aResume
=
new
Resume
();
aResume
.
setName
(
"大鸟 "
).
setGender
(
"男 "
).
setAge
(
25
);
aResume
.
setWorkExperience
(
"1999-2002, "
,
"XX公司"
);
Resume
bResume
= (
Resume
)
aResume
.
clone
();
bResume
.
setWorkExperience
(
"1999-2002, "
,
"YY公司"
);
Resume
cResume
= (
Resume
)
aResume
.
clone
();
cResume
.
setWorkExperience
(
"1999-2002, "
,
"ZZ公司"
);
System
.
out
.
println
(
">>>>>>浅度拷贝:"
);
aResume
.
display
();
bResume
.
display
();
cResume
.
display
();
}
public
static
void
deepCopy
()
throws
CloneNotSupportedException
,
ClassNotFoundException
,
IOException
{
Resume
aResume
=
new
Resume
();
aResume
.
setName
(
"大鸟 "
).
setGender
(
"男 "
).
setAge
(
25
);
aResume
.
setWorkExperience
(
"1999-2002, "
,
"XX公司"
);
Resume
bResume
= (
Resume
)
aResume
.
deepClone
();
bResume
.
setWorkExperience
(
"1999-2002, "
,
"YY公司"
);
Resume
cResume
= (
Resume
)
aResume
.
deepClone
();
cResume
.
setWorkExperience
(
"1999-2002, "
,
"ZZ公司"
);
System
.
out
.
println
(
">>>>>>深度拷贝:"
);
aResume
.
display
();
bResume
.
display
();
cResume
.
display
();
}
public
static
void
main
(
String
[]
args
)
throws
CloneNotSupportedException
,
ClassNotFoundException
,
IOException
{
// 浅度拷贝
shallowCopy
();
System
.
out
.
println
(
"=================================="
);
// 深度拷贝
deepCopy
();
}
}
Back
|
FazBrowse Home
|
New Git URL