So I recently came accros this. I was creating an if-else-statement with as it's condition a final boolean variable. Eclipse immediatly told me that the else part of the code was unreachable and therefore dead code. This was my code(compacted).
public static void main(String[] args){
final boolean state = true;
if(state == true){
System.out.println("A");
}else{
System.out.println("B");
}
}
Then I though what would happen if the code stayed the same but the variable wasn't final anymore? So I tried that and this was what happened, nothing no warnings or errors. The code:
public static void main(String[] args){
boolean state = true;
if(state == true){
System.out.println("A");
}else{
System.out.println("B");
}
}
Now I'm wondering, why is the first case detected and flagged and the second case not?
Thank you in advance.