I know that a void method does not return any value, but I can still write code like
void nothingDohere() {return;}
So, How can “void” work with the “return” statement here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A return statement without a value can only be used in a
voidmethod (or a constructor), and simply performs the “get out of the method now” part of returning. Think of a return-with-value statement has having two purposes:finallyblocks of course)The return statement in a
voidmethod simply achieves the first of these; the second makes no sense in avoidmethod.From section 14.17 of the Java Language Specification: