How do I check if a method returns true or false in an IF statement in Java?


Let's say I have a boolean method that uses an if statement to check whether the return type should be true or false:

public boolean isValid() {
   boolean check;
   int number = 5;

   if (number > 4){
      check = true;
   } else {
      check = false;
   }

 return check;

And now, I want to use this method as a parameter of an if statement in a different method:

if(isValid == true)  // <-- this is where I'm not sure
   //stop and go back to the beginning of the program
else
   //continue on with the program

So basically what I'm asking is, how do I check what the return type of the boolean method within the parameters of an if statement is? Your answers are deeply appreciated.


Answers:


Since it's a method, to call it you should use parens afterwards, so your code would then become:

if(isValid()) {
    // something
} else {
    //something else
}