總結(jié)Java會(huì)出現(xiàn)"unreachable code"錯(cuò)誤的幾個(gè)例子
1. throw關(guān)鍵字
Java代碼:
- public void XXX() throws Throwable{
- throw new Throwable();
- System.out.println("test");
- }
2. return關(guān)鍵字
Java代碼:
- public void XXX() {
- return;
- System.out.println("test");
- }
3. continue關(guān)鍵字
Java代碼 :
- public void XXX() {
- for(int i=0; i<10; i++) {
- continue;
- System.out.println("test");
- }
- }
4. break關(guān)鍵字
Java代碼:
- public void XXX() {
- for(int i=0; i<10; i++) {
- if(i==5) {
- break;
- System.out.println("test");
- }
- }
- }
posted on 2013-01-10 12:32 你爸是李剛 閱讀(1225) 評(píng)論(1) 編輯 收藏