dead code,即死代码,无作用的代码
if (true & true) {
System.out.println("execute ok");
} else {
System.out.println("execute fail");
}
从else开始即为无效代码。
因为true&true在编绎时即知结果,所以else部分是无用的,编译器知道肯定不会执行的代码。
如果换成以下代码:
boolean a = true;
boolean b = true;
if (a & b) {
System.out.println("execute ok");
} else {
System.out.println("execute fail");
}
则不会出现该问题,因为在编译时编译器不确定a & b是否恒成立。
Unreachable Code:无法执行到的代码:
public boolean isParallel(Line l1,Line l2) {
return false;
if(l1.slope==l2.slope){
return true;
}
上面已经确定return false;
所以以下的任何代码都无法执行到。