I've just learned that |
is used to catch multiple exceptions in the same block; |
is the bitwise operator for OR. In this case, is it still used as a bitwise operator or does it have a different meaning when in context?
If a catch block handles multiple exceptions, you can separate them using a pipe (|) and in this case, exception parameter (ex) is final, so you can't change it. The byte code generated by this feature is smaller and reduce code redundancy.
Java allows you to catch multiple type exceptions in a single catch block. It was introduced in Java 7 and helps to optimize code. You can use vertical bar (|) to separate multiple exceptions in catch block. An old, prior to Java 7 approach to handle multiple exceptions.
Bitwise operators are used to performing the manipulation of individual bits of a number. They can be used with any integral type (char, short, int, etc.). They are used when performing update and query operations of the Binary indexed trees.
In this case, is it still used as a bitwise operator or does it have a different meaning when in context?
It has a different meaning - although it's of the same "flavour" in that it's "if exception X is caught, or exception Y is caught, or exception Z" is caught.
In the JLS section 14.20 the |
is just included literally in the grammar - it's not the OR operator in this context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With