java - How can I check if one value is A or B and another value is A or B? -
i'm trying effect of:
if (firstchoice == || b && secondchoice == || b){     //passes check. } logically, want pass if first , second choice either or b. syntax valid? there better way it?
you can't == || b; can (but shouldn't, see below):
if ((firstchoice == || firstchoice == b) &&     (secondchoice == || secondchoice == b)) { that's readable you're going it. breaking on line makes easier follow logic; horizontal scrolling bad thing, , breaking @ && operator readable way.
however, there's way make more readable: create helper method, want.
private boolean isaorb(yourobject choice) {     return choice == || choice == b; } then if statement be:
if(isaorb(firstchoice) && isaorb(secondchoice)) { this more readable future readers, including yourself, you're going here.
Comments
Post a Comment