我只是想知道爲什麼這段代碼會拋出一個錯誤。錯誤是:爲什麼會給出錯誤?
「異常線程 」線程1「 java.lang.Error的」
class Salmon extends Thread
{
public static long id;
public void run()
{
for(int i = 0;i<4; i++){
if(i==2&& id ==Thread.currentThread().getId()){
//if(i==2){
new Thread(new Salmon()).start();
throw new Error();
}
System.out.println(i + " ");
}
}
public static void main(String[] args)
{
Thread t1 = new Salmon();
id = t1.getId();
t1.start();
}
}
你得到的錯誤是什麼 – developer 2012-07-24 17:16:10