我不明白爲什麼我們不能做到以下幾點:Java接口擴展Cloneable的
interface MyInterface extends Cloneable {}
class myClazz implements MyInterface {
public Object clone() { return null; }
}
class test{
public static void main(String[]a){
MyInterface o = new myClazz();
o.clone(); // IMPOSSIBLE
}
}
但是,這將很好地工作
interface Misc{
public void testM();
}
interface MyInterface extends Misc{}
class myClazz implements MyInterface {
public void testM() {}
}
class test{
public static void main(String[]a){
MyInterface o = new myClazz();
o.testM(); // OK
}
}
與Cloneable的發生什麼事?
感謝,
將Clone()方法添加到MyInterface接口。 – MeBigFatGuy 2011-05-10 15:26:14