public class CloneMainCls {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
MyNumbers mn = new MyNumbers();
MyNumbers mn2 = (MyNumbers) mn.clone();
mn2.getNumbers()[1] = 3;
System.out.println(mn.getNumbers()[1] + ":" + mn2.getNumbers()[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class MyNumbers implements Cloneable{
private int[] numbers = null;
MyNumbers(){
numbers = new int[]{0,1,2,3,4,5,6,7,8,9};
}
@Override
protected Object clone() throws CloneNotSupportedException {
MyNumbers numbers2 = (MyNumbers)super.clone();
numbers2.numbers = (int[]) numbers.clone();
return numbers2;
}
public int[] getNumbers() {
return numbers;
}
}
'자바 > 자바팁' 카테고리의 다른 글
서버에 JNDI 설정 세팅하기 (0) | 2015.01.03 |
---|---|
[펌]Java 예제 - Queue(큐) Class (0) | 2014.12.01 |
svn 관련 팁 (0) | 2012.04.05 |
NIO 간단한 파일읽기 예제 (0) | 2012.01.19 |
NIO가 무엇일까요? (1) | 2012.01.18 |