내부 속성이 똑같은 두 클래스간의 캐스팅 테스트
public class TestChild {
private String name;
public TestChild(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class Test2 implements Cloneable {
private String name;
public Test2(String name) {
this.name = name;
}
@Override
public TestChild clone() {
TestChild clone = (TestChild) super.clone();
return clone;
}
}
public static void main(String[] args) throws CloneNotSupportedException {
Test2 test2 = new Test2("test2");
TestChild testChild2 = test2.clone();
System.out.println(testChild2.getName());
}
//결과
//ClassCastException 발생Last updated