Java之dead code——無用代碼
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是否恒成立。
原帖地址:https://hi.baidu.com/nicker2010/item/c00c521f01f1eeaffeded596
最後更新:2017-04-03 16:49:10