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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -