Community
Participate
Working Groups
Build: 2.0 If I compile a class with the following method: protected int foo() { while (5 < 10) { System.out.println("Foo"); } } It reports no compilation errors. However, this method declares a return type, but there is no return statement. I would expect either, "this method must return a result of type int", or "this method has no way to return". I don't know if the latter condition is specified in the language, so maybe it's better to go with the first message.
No. This code is legite due to the infinite loop. Put it this way: there is no way you can exit the method without returning something, given you cannot reach the method exit (without an exception).
Closing
here's your reference Peter http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37316
i meant: John. sorry
Thanks Adam. I looked through JLS but didn't find that section. That clears it up.