I have a very silly question for you :)
For example, I have following code snippet:
class MyClass {
public static void main (String[] args) {
final String status;
try {
method1();
method2();
method3();
status = "OK";
} catch (Exception e) {
status = "BAD"; // <-- why compiler complains about this line??
}
}
public static void method1() throws Exception {
// ...
}
public static void method2() throws Exception {
// ...
}
public static void method3() throws Exception {
// ...
}
}
The question is inside: why compiler complains about this line?
IntelliJ IDEA says, that Variable 'status' might already have been assigned to.
But, as I can see, we don't ever reach line (where we set status = "OK") in case of exceptional situation. So the status variable will be BAD and everything should be ok. And if we don't have any exception, then we get OK. And we will set this variable only ONCE a time.
Any thoughts about this?
Thanks for your help!