I have a reproducible test case:
public class TestCase {
private final java.util.function.Consumer<Object> emptyCallback = result -> {};
public TestCase() {
return;
}
public static void main(String... args) {
new TestCase();
}
}
Using Java 8, update 51 (Oracle JDK). This can't be compiled, using both IntelliJ and javac.
IntelliJ output:
Error(6, 7): java: variable result might not have been initialized
javac output:
TestCase.java:6: error: Variable result might not have been initialized
return;
^
1 error
Now what is strange, is that removing return;
or the Consumer
will fix the error. Is this a java bug, or is there something of the language design that I am missing here?
Edit: This is not a duplicate of How can a constructor return a value, this is actually a constructor and isn't about the return value of constructor but variable initialization.