aspose file tools
The moose likes Beginning Java and the fly likes A boolean method and it�s returns values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "A boolean method and it�s returns values" Watch "A boolean method and it�s returns values" New topic
Author

A boolean method and it�s returns values

Ilh Oleo
Ranch Hand

Joined: Feb 07, 2007
Posts: 57
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

Joined: Jan 17, 2006
Posts: 1295
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.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ilh Oleo
Ranch Hand

Joined: Feb 07, 2007
Posts: 57
But i�m passing the value of tama�oajugar from another class so it will execute it�is it?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
How many times would the for loop execute under these circumstances:

Ilh Oleo
Ranch Hand

Joined: Feb 07, 2007
Posts: 57
none what about the {false,false} arguments???
[ April 08, 2007: Message edited by: Ilhuicahua Xicohtencatl ]
Ilh Oleo
Ranch Hand

Joined: Feb 07, 2007
Posts: 57
I�m trying this and it�s working but why the other code doesn�t work???
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9956
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: A boolean method and it�s returns values
 
Similar Threads
Regex: find() method
Thread question: Please help
Help with an iteration
Regex ???
Logical operator precedence