Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Missing return statement  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
I am trying to return an array from a simple method but can't figure out why it's throwing a "missing return statement error". Have I gone blind?

 
Saloon Keeper
Posts: 4345
108
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return statement is currently inside the loop - it should be outside (after) the loop.
 
Marshal
Posts: 58421
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
You would have found the error for yourself if you had indented the code properly. If the array passed to that method has a length of 0, then the loop will never start, and the return statement will never be reached.
 
Dale Herring
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks brosef
 
Campbell Ritchie
Marshal
Posts: 58421
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!