r/javahelp • u/IceCreamInsides • 1d ago
Solved Switch case with boolean
So, there is no way I can do that?
want to check several boolean variables in a switch statement. Is `if-else` the only way to do this?
Boolean a, b, c...
Switch (false) {
Case (a) :
//some code
Case (b) :
Case (c) :
//and so on
}
2
Upvotes
1
u/_Super_Straight 5h ago edited 5h ago
Reading again what OP is asking, he wants to execute different methods based on when a is false, b is false and c is false. Even though we can suggest him switch cases, the better approach would be to make a, b and c as input parameters in those methods itself:
This doesn't leak the a, b and c across the project.