Why does this not compile (tried with java 8 and java 10)? It yields a missing return statement error.
public class CompilerIssue {
public boolean run() {
throwIAE();
// Missing return statement
}
public void throwIAE() {
throw new IllegalStateException("error");
}
}
The java compiler does not know that the
throwIAE
will always throw an exception so it
assumes that you will eventually reach the end of the
run
method and,
when that happens,
a return value is required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With