Reputation: 6617
What does return ;
mean?
As far as I can tell, it means to return void
.
public void method()
{
System.out.println("here2");
return ;
}
Can anybody please explain?
Upvotes: 2
Views: 2328
Reputation: 2579
We are simply just returning the CONTROL to the calling function.
Upvotes: 0
Reputation: 223277
It means to return nothing - void
to be specific. Used to return out of method. It is used with method with return type void
, if you want to return early from the method based on some condition like:
public void method(int parameter)
{
if(parameter < 0)
return;
//otherwise continue with the following.
System.out.println("here2");
}
In your current code, you are not required to write return
since the method will return normally from the last line of code.
Returning a Value from a Method
Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method
Upvotes: 11