What is a name | operator in java

In java 7, we can track multiple exceptions at a time like

try {  
    Class a = Class.forName("wrongClassName");  
    Object instance = a.newInstance();  
} catch (ClassNotFoundException | IllegalAccessException |  
   InstantiationException ex) {  
   System.out.println("Failed to create instance");  
}  

      

Is this bitwise inclusive OR? As far as I know in java, bitwise operators are used to compare binaries. If it is not, then how does java differentiate this operator with Bitwise Inclusive OR?

Just want to know the name of the operator used here and this operator exists before java 7.

Any answer is appreciated. Thank you.

+3


source to share


4 answers


It is valid as of Java 7 and I call it a pipe.

The catch block itself is called a multi-catch block.



This operator is a bitwise or multi-user operator, depending on the context in which it is used. As in (1 + 1)

, the operator +

is the addition operator, and in "hello" + "world"

the + operator is the concatenation.

+5


source


docs said:

The catch clause specifies the types of exceptions that the block can handle, and each type of exception is separated by a vertical bar (|).



This operator is used as a bitwise inclusive OR before Java 7.

+5


source


It is unnamed (in this context)

An exception parameter can denote its type as a single class type, or the union of two or more class types (called alternatives). The union alternatives are syntactically separated by :.

Ref: Java Language Specification Chapter 14.20

+1


source


The operator exists as a (not short-circuiting) OR operator before Java 7, and that's probably why it was used here - you catch one exception, or the other, OR the other, etc.

0


source







All Articles