Return statement only in while loop
How should we interpret
If a method is declared to have a return type (§8.4.5), then a compile-time error occurs if the body of the method can complete normally (§14.1).
(https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.4.7)?
javac rejects
public int foo() {
if (true) {
return 1;
}
}
but allows
public int foo() {
while (true) {
return 1;
}
}
and similar constructs where the expression of the while loop can be folded to a true boolean.
Are we allowed to reject such while constructions as well as long as there is no return after the while loop?
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information