Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

return statement in a void method?  RSS feed

 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment where I need to modify a method, which they already put an if-statement in there... if the condition not met, it gives a return, but it is a void method. What does a return do in a void method?

eg:

 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It returns.

All jokes aside, it stops execution of the method and returns control to the calling code, as if the end of the method body had been reached.
 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh, got it... thanks!
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is another way to get the same result. I am assuming you have a simple if rather than if-else.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!