考虑这个函数:
public boolean foo(){
System.exit(1);
//The lines beyond this will not be read
int bar = 1; //L1
//But the return statement is required for syntactically correct code
return false; //L2
//error here for unreachable code
//int unreachable = 3; //L3
}
有人能解释一下为什么 L1 和 L2 明显不可达时不会发出警告,但 L3 会吗?
System.exit()
修改为NOP(无操作)。现在,它可能会抛出安全异常或线程终止异常。 - bestsss