This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question about return?  RSS feed

 
Maxwell Wood
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
when is it legal to use return;
other than in a catch block
 
Devaka Cooray
Marshal
Posts: 5613
742
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you practically tried that?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16043
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a return statement to return from a method. You can use it anywhere in a method - not just in a catch block (in fact, catch blocks don't have anything in particular to do with the return statement).

Ofcourse, if your method has a return type other than void, you must specify a value to return in the return statement.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a return statement in a constructor too...
 
sakthi moorthy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:You can use a return statement in a constructor too...


class ReturnInConstructor {

public ReturnInConstructor() {
return ;
}




}



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!