-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreboard.java
More file actions
59 lines (45 loc) · 1.11 KB
/
Copy pathScoreboard.java
File metadata and controls
59 lines (45 loc) · 1.11 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
package com.javaex.api.objectclass.ex05;
import java.util.Arrays;
public class Scoreboard implements Cloneable {
private int scores[];
// 생성자
public Scoreboard(int[] scores) {
this.scores = scores;
}
public Scoreboard getClone() {
Scoreboard clone = null;
try {
clone = (Scoreboard)clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return clone;
}
@Override
public String toString() {
String output = "Scoreboard(";
for(int i = 0; i < scores.length; i++) {
output += scores[i];
if (i < scores.length - 1) {
output += ",";
}
}
output += ")";
return output;
}
public int[] getScores() {
return scores;
}
public void setScores(int[] scores) {
this.scores = scores;
}
@Override
protected Object clone() throws CloneNotSupportedException {
// 먼저 얕은 복제를 시도
Scoreboard clone = (Scoreboard)super.clone();
// 내부 참조 객체 복제 시도
clone.scores = Arrays.copyOf(scores, scores.length);
// return super.clone();
return clone;
}
}