CKTIS / Java
Bitwise OR operator (|)
The | operator combines corresponding integer bits: a result bit is 1 when at least one input bit is 1. With boolean operands, it performs logical OR without short-circuiting.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
left | rightThe | operator performs bitwise inclusive OR: 0 | 0 produces 0, while every other bit pair produces 1. Use it to combine masks and set flags without clearing bits already set.
Integral operands undergo binary numeric promotion. If either operand is long, the other is widened directly to long if needed, and the result is long. If neither operand is long, any byte, short, or char operand is widened to int, and the result is int. Wrappers are unboxed; null then causes NullPointerException. The types float and double are not allowed.
For boolean or Boolean operands, the result is boolean. Unlike ||, | also evaluates the right operand even when the left is true, provided left-operand evaluation completes normally. Do not mix boolean and integral operands.
Examples
public class Main {
public static void main(String[] args) {
int flags = 0b0101;
int mask = 0b0011;
int combined = flags | mask;
System.out.println(combined);
}
}Result
7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.