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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -