wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes void return difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "void return difference" Watch "void return difference" New topic
Author

void return difference

Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Is there any difference between --
void abc() { return; }
AND
void abc() {}
Regards,
Arijit


Regards,<br /> Arijit
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
void abc { return } would give you error, if method is void it doesnt return anything.


SCJP 1.4<br />SCWCD 1.3
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Did not understand your reply Mehta...
Why should it give error ? I am returning void! Isn't it ? In fact if you try out an example you will find that there is no error.
I was interested to know whether there is any difference in garbage collection or any other memory issue related to that.
Regards,
Arijit
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
If you get to the end of a void function, there is an implicit "return" . So it makes no difference whether you put it there or not.
Garbage collection is not an issue, since you haven't created any objects.
[ October 31, 2002: Message edited by: Ron Newman ]

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Sorry I guess I should have explained my query more elaborately....
void abc() {
// Lot of oject creations and manipulations
return;
}
void abc() {
// Lot of oject creations and manipulations
}

Any difference in memory issues or garbage collection issues now ?
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
No. When you get to the end of a method, you return. If the method is void, then the return statement is optional. If the method returns a value, the compiler will complain if you don't have a return statement.
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: void return difference