Item 13. clone
Cloneable
public interface Cloneable {
// ์ด๋ค ๊ตฌํ๋ ๋์ด ์์ง ์์
}Cloneable ์ธํฐํ์ด์ค์ ์ญํ
class NotCloneable {
int x;
int y;
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
class Cloneable implements java.lang.Cloneable {
int x;
int y;
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
class Main {
public static void main(String[] args) throws CloneNotSupportedException {
Cloneable cloneable = new Cloneable();
NotCloneable notCloneable = new NotCloneable();
cloneable.clone(); // OK
notCloneable.clone(); // CloneNotSupportedException
}
}Object.clone
์ฌ๋ฐ๋ฅธ Cloneable ๊ตฌํ ๋ฐฉ๋ฒ
๊ฐ๋ณ ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ํ๋๊ฐ ์๋ ํด๋์ค์ clone
๊ฒฐ๋ก
Last updated