If you have a void method then you can use return; but you do not have to and many times people don't.
If you have a method which returns a value that you need to use return JavaObject; in that method.
The returned value can be an valid Java object including exceptions, primitives and user defined objects.
Two choices: A) Learn from mistakes. B) Don't make mistakes.
The return; statement on its own doesn't return void; it transfers program control back to whichever code called the current method. It should be obvious that it can only be used in a method with void instead of a return type.
The statement return 1; both transfers control back to the calling method and leaves the value 1 on the stack for the calling method to use; it can only be used in a method with a return type consistent with int.
He's my best friend. Not yours. Mine. You can have this tiny ad: