4 ms·
I'm having trouble constructing a specific example that doesn't work, can you provide a minimal example that fails to compile? This compiles fine in Java 11, fo
by kaashif 4y ago
I'm having trouble constructing a specific example that doesn't work, can you provide a minimal example that fails to compile? This compiles fine in Java 11, for example:
import java.io.IOException;
class Test {
int g() throws IOException {
throw new RuntimeException("aaa");
}
int f() throws IOException {
int x;
try {
x = g();
} catch (IOException e) {
x = 3;
}
return x;
}
}
So the compiler definitely believes that x is initialized because we can return it.
Not a Java expert so maybe there's some subtlety I'm missing.
- layer8 4y agoSorry, I had slightly misremembered, please see my corrected comment above. The second assignment is seen as a reassignment when the variable or field is final.