Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to compare multiple (non-boolean) things at once using | or & in Java, similar to how you can catch multiple exceptions using |? [duplicate]

Normally, I would have to type something like

if(a == x || b == x) {...}

But I saw that when using try/catch blocks, you can do stuff like this:

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {}

Is there something similar I can do with equality statements, like

if((a | b) == x) {...}

?

like image 845
user8578415 Avatar asked Dec 04 '17 14:12

user8578415


1 Answers

No. The least you can do is ||. Other than multi catch block, operator | gets treated as bitwise OR and that is not what you needed. Inshort NO.

like image 69
Suresh Atta Avatar answered Nov 10 '22 16:11

Suresh Atta