This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

void return difference

 
Arijit Ghosh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any difference between --
void abc() { return; }
AND
void abc() {}
Regards,
Arijit
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void abc { return } would give you error, if method is void it doesnt return anything.
 
Arijit Ghosh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Arijit Ghosh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic