測試用例(JDK的版本:ORACLE 1.6.0_31)的對象clone()方法不拋出的RuntimeException被稱爲上類未實現了Cloneable
public class TestCloneable{
public TestCloneable clone(){
return new TestCloneable();
}
}
public static void main(String[] args) {
TestCloneable testObj = new TestCloneable();
TestCloneable testObj2 = new TestCloneable();
System.out.println(testObj.clone());
Hashtable<Integer, TestCloneable> ht = new Hashtable<Integer, TestCloneable>();
ht.put(1, testObj);
ht.put(2, testObj2);
System.out.println(ht.clone());
HashMap<Integer, TestCloneable> hm = new HashMap<Integer, TestCloneable>();
hm.put(1, testObj);
hm.put(2, testObj2);
System.out.println(hm.clone());
}
無這些線中的給CloneNotSupportedException的運行時,其上矛盾Java規範克隆方法:
/**
* @exception CloneNotSupportedException if the object's class does not
* support the Cloneable
interface. Subclasses ...
*/
哪裏出錯?
在使用克隆嗎?一般來說,克隆有點破損。 – 2012-03-27 15:35:02
一般來說。我的意思是它是我在使用克隆中的錯誤還是在jdk中的一些錯誤? – Egor 2012-03-27 15:38:27