Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Multiple exit statements in a method - good or bad practice

818236Mar 7 2011 — edited Mar 9 2011
Hi Java-lovers,

I happened to read through this article: http://www.theserverside.com/tip/A-return-to-Good-Code on "theserverside.com" about how having multiple exit statements in a method is bad coding practice.

However when you glance through the comments on the article, you will find people showering mixed reactions on that statement.

I want to know what should be the proper road to take while writing code.
Is there a logic which should decide which method to follow?

Thanking you in advance for your able guidance.

Searching over google I found the following links:
http://stackoverflow.com/questions/2939162/is-it-bad-to-have-multiple-return-statements
http://stackoverflow.com/questions/36707/should-a-function-have-only-one-return-statement

Static code analyzers will point out multiple exit statements as a negative pointer!
This post has been answered by YoungWinston on Mar 7 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2011
Added on Mar 7 2011
33 comments
757 views