File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of return statement in method which return type is void

 
kandarp mehta
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method which return type is void. But if I put return statement in that method, java will accept it. I just want to know that what is the use of return statement in void method?



Please help me to know this java future.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your example, it's useless; the method returns automatically from the method anyway, so there's no need to add a return statement explicitly.

However, sometimes you want to return before the end of the method. To do that, you can add a return statement. The only difference between doing this between a void and non-void method is that in the void method, you don't add an expression after the return keyword.

Simple example:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic