8

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) {...}

?

user8578415
  • 341
  • 1
  • 4
  • 8
  • 2
    Unfortunately not. What you saw is just the syntactic sugar added in 1.7 for `multi-catch`. Boolean expressions can't be chained like that. – QBrute Dec 04 '17 at 14:32
  • 2
    As per [this high voted comment](https://stackoverflow.com/a/3495968/314291), it was perhaps unfortunate for Java 7 to choose bitwise or when catching multiple exceptions. It was always going to create confusion. – StuartLC Dec 04 '17 at 14:32

1 Answers1

5

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.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307