I have this very simple code snippet:
static String getInput() throws IOException{
if(in.ready()){
return in.readLine().trim();
}
System.err.println("Please provide more input in order to execute the program.");
System.exit(0);
return "";
}
By what I think I know, there is no possible way that the JVM will execute the return statement at the end of the code. But if I comment this line out, java will complain about a missing return statement. Why doesn't the JVM recognize that a System.exit(0) will not allow any other code to execute, but complains about unreachable statements if a return will not allow code to be executed? I think the return statement at the end is redundant and might be confusing to other devs, so why won't java let me get rid of it?