看板 java 關於我們 聯絡資訊
是講 Thread Which two code fragments will execute the method doStuff() in a separate thread? (Choose two) A. new Thread(){ public void run(){doStuff();} }; B. new Thread(){ public void start(){doStuff();} }; C. new Thread(){ public void start(){doStuff();} }.run(); D. new Thread(){ public void run(){doStuff();} }.start(); E. new Thread( new Runnable() { public void run(){doStuff();} }).run(); F. new Thread()( new Runnable(){ public void run(){doStuff();} }).start(); 我要問我把 E,F 丟給 compiler, 在 main 中放入上面選項的程式碼, 外面實作 doStuff(): public static void doStuff(){ System.out.println("Hi"); } 竟然 E 可以執行, A ~ E 都用相同方法卻可以通過編譯, 但 F 卻出現 "未對類型 new Runnable(){} 定義方法 start()" 的錯誤, 這是怎麼一回事? ~ ~ ~ ~ ~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.116.192.206
LPH66:有Thread.start()但沒有Runnable.start() 05/07 01:50