• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about return?

 
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: 5209
508
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: 15758
74
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: 9597
36
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 ;
}




}



 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!