• Post Reply Bookmark Topic Watch Topic
  • New Topic

A boolean method and it�s returns values  RSS feed

 
Ilh Oleo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i�m almost done with my project and thanks to all and your support!!
Just one method to finish and ...to study for my finals
Here i have this method but it�s bugging me because it says that must return a boolen values which does.
Another thing : it matters if I pass the array "validacion" already declared without the "[]"??



Error:This method must return a result of type boolean
What?? If i�m doing that!!!

[ April 08, 2007: Message edited by: Ilhuicahua Xicohtencatl ]
[ April 08, 2007: Message edited by: Ilhuicahua Xicohtencatl ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the for loop never executes (for instance if tama�oajugar is <= 0) then the compiler sees that nothing will be returned. You must return a boolean value, or throw an exception, for all possible execution paths.

Now you may be thinking that tama�oajugar will never be less than or equal to 0, but the compiler cannot infer that and therefore returns a compile time error.
 
Ilh Oleo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i�m passing the value of tama�oajugar from another class so it will execute it�is it?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many times would the for loop execute under these circumstances:

 
Ilh Oleo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
none what about the {false,false} arguments???
[ April 08, 2007: Message edited by: Ilhuicahua Xicohtencatl ]
 
Ilh Oleo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�m trying this and it�s working but why the other code doesn�t work???
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code works because you are garanteed to hit that "return bandera;" line.

your other code example has a way for no "return xxx" to be hit. Garret said as much in his post. The compiler can't know what value will be passed in. all it knows is that if, somehow, someone passes in a 0 or less (which is a perfectly valid int), the compiler has nothing to return.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!