I know there are a couple of questions on stackoverflow dealing with the problem of already initialized variables but I could not find anything answering my question with regards of local variables. Consider the following excerpt:
public class Test {
public static void main() {
final int i;
try {
i = computeI();
} catch (Exception e) {
i = 5;
}
}
private static int computeI() throws Exception {
return 3;
}
}
The java compiler (openjdk-8-jdk) tells me i = 5 Variable i might already have been initialized but there is no way where i could have been assigned.
Question: Is there a way how i could have been initialized that a do not know of (since it's a local variable another thread cannot interfere to my knowledge). If not, why does the compiler issue this warning?
static. There a tons of answers to this topic - Murat Karagöz