Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return problems

 
adam faith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem with some of my code and i just cant see what going on...

I am calling this method, Drawable is an interface and in the if i am checking if the coordinate object passed is within the shape of an object drawn before.
But i keep getting method does not return a value, can sombody please help
 
Garion Winters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you notice your return part of code is within an if clause. What happens IF the case isn't true? Then nothing is returned. Hope that helps.
 
adam faith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i added an else with a return but its not made a difference and if i add a continue then i might get caught in an infinite loop
 
Garion Winters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the same kind of problem, different loop. Your program says: while(iter.hasNext())
What if iter doesn't have a next? Then it won't even execute the if nor the else part. See what I mean? It would avoid it altogether and jump out of the while loop and return nothing. Sorry for missing that!
 
adam faith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, its clicked, thanks
 
Wilfried LAURENT
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people said a better way to code would have been only to have a single return statement like:

W.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic