Make a Custom Conditional Statement - Java

517 Views Asked by At

Is there a way to make a custom conditional statement? Or is this not possible and I would have to just put the function inside of an if.

For example:

customConditional(bar){
    //run this code
}

Where if bar was 1 it would execute the code and any other number wouldn't.

Edit: What I was trying to say was, how are conditionals defined and is there a way to define another one?

1

There are 1 best solutions below

2
On

No need to do that, all you need is a method that will return a true/false statement then use it inside an if condition:

Example:

private boolean myOwnMethod(int bar) {
    return bar == 1;  //this check can be as simple or complex as you need
}

Usage:

if (myOwnMethod(bar)) {
    //run this code
}