0
는 의심의 여지가개체 복제 오류
public class A implements Cloneable{
public static void main(String[] args) {
A a1 = new A();
try {
A a2 = (A) a1.clone();//works fine
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
B b1 = new B();
B b2 = (B) b1.clone();//cannot get this method
}
}
class B implements Cloneable {
}
이 코드는 내가 두 클래스를 모두 알고있는 오류를
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type Object is not visible
을 다음있어 컴파일 된 날 때 2 개 클래스 클래스 A와 B를 갖는 설명하게 저를 명확히하십시오이 확장 Java.lang.Object
클래스 이유를 설명하십시오 class B
clone()
방법을 얻을 수 없습니다
IIRC 복제를 허용하려면 몇 가지 특수 인터페이스를 구현해야합니다. "Cloneable"또는 확실하지 않은 것 – MightyPork
여기에 내부 클래스가 없습니다. – EJP