爲什麼下面的代碼在JDK7中拋出CloneNotSupportedException但是不在JDK6中?CloneNotSupportedException即使在執行Cloneable時
public class DemoThread extends Thread implements Cloneable {
/**
* @param args
*/
public static void main(String[] args) {
DemoThread t = new DemoThread();
t.cloned();
}
public DemoThread cloned()
{
try {
return (DemoThread) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
顯然,方法根據javadocs中的以下理由進行了更改:'拋出CloneNotSupportedException,因爲線程無法被有意克隆。' –
將幫助您包含堆棧跟蹤 – radai