In testOne:
- Why is the "else if" not unreachable (aNumber is final so the compiler should know it can't get past the "if" part, but it only gives a warning)?
- Since "else if" apparently is reachable, why then is the "else" part not unreachable ("else if" is always true)?
In testTwo:
- The "if (true)" is unreachable.
Is all this because the compiler somehow thinks my variable and boolean can change even if they are final("aNumber") and hardcoded("true"). And when there is no variable or boolean (the first "else" in testTwo) nothing can change, and since it mops up all possibilities by just saying "else" it knows it cant reach anything further down?
public int testOne() {
final int aNumber = 5;
if (aNumber < 10) {
return 0;
} else if (true) {
return 2;
} else {
return 3;
}
}
public int testTwo() {
final int aNumber = 5;
if (aNumber < 10) {
return 0;
} else {
return 1;
}
if (true) {
return 3;
} else {
return 4;
}
}