Контрольный пример (версия jdk: oracle 1.6.0_31)
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 для метода клонирования: <pre>
/**
* @exception CloneNotSupportedException if the object's class does not
* support the <code>Cloneable
интерфейс.Подклассы ... * /
Где ошибка?