当前位置:编程学习 > JAVA >>

总结Java会出现"unreachable code"错误的几个例子

1. throw关键字
Java代码:  
public void XXX() throws Throwable{  
    throw new Throwable();  
    System.out.println("test");  
}  
2. return关键字
Java代码 : 
public void XXX() {  
    return;  
    System.out.println("test");  
}  
3. continue关键字
Java代码:  
public void XXX() {  
    for(int i=0; i<10; i++) {  
        continue;  
        System.out.println("test");  
    }  
}  
4. break关键字
Java代码:  
public void XXX() {  
    for(int i=0; i<10; i++) {  
        if(i==5) {  
            break;  
            System.out.println("test");  
        }  
    }  
}  
5. while(true):
Java代码:  
public static void XXX() {  
    while(true);  
    System.out.println("when?");  
}  
 
补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,