aspose file tools*
The moose likes Beginning Java and the fly likes return problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return problems" Watch "return problems" New topic
Author

return problems

adam faith
Greenhorn

Joined: Aug 24, 2002
Posts: 22
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

Joined: Oct 01, 2002
Posts: 20
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

Joined: Aug 24, 2002
Posts: 22
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

Joined: Oct 01, 2002
Posts: 20
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

Joined: Aug 24, 2002
Posts: 22
Okay, its clicked, thanks
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
Some people said a better way to code would have been only to have a single return statement like:

W.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: return problems