低垂让我们说Class B
延伸class A
和class A
是可复制如下:爪哇 - 克隆
public class A implements Cloneable {
public Object clone() throws CloneNotSupportedException {
A ac = (A) super.clone();
return ac;
}
}
public class B extends A {
public Object clone() throws CloneNotSupportedException {
B a = (B) super.clone();
return a;
}
}
为什么它是合法的从A到B的下一行进行垂头丧气:
B a = (B) super.clone(); // (super of B is A)
而下一个下降是运行时错误?
A a = new A();
B b = (B) a.clone();
在此先感谢!
你的意思是'B b = new B();'和'A a =(A)b.clone();'有没有机会? – blalasaadri
有关克隆()的优秀问题,这也是我无法包裹头部的问题。 – raiks