try {
Thread.sleep(333);
} catch (InterruptedException e) {
e.printStackTrace();
}
我可以用某種方式上面的try/catch使用像trySleep(Thread.sleep(333));
創建的方法會做同樣的原始試試?
使用的例子:
public class Test implements Runnable {
public Test() {
Thread thisThread = new Thread(this);
thisThread.start();
}
@Override
public void run() {
while (true){
System.out.println("Testing");
trySleep(Thread.sleep(333));
}
}
public void trySleep(/*Thread object*/){
//Code for try/catch
}
public static void main(String[] args) {
new Test();
}
}
當然上面的代碼將無法編譯,它只是一個問題。
我想要這種事情的原因是因爲我覺得try/catch的東西太混亂了,並且很煩人。
你是什麼原因不內聯這個聲明? – 2015-04-05 23:06:31