> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Bitwise OR Assignment

The `|=` operator is a compound assignment operator that performs an inclusive OR operation between the left and right operands, subsequently assigning the computed result to the left operand. Depending on the data types of the operands, it functions as either a bitwise OR (for integral types) or a strict logical OR (for boolean types).

## Syntax and Equivalence

```java theme={"dark"}
leftOperand |= rightOperand;
```

Internally, the Java compiler evaluates `A |= B` as:

```java theme={"dark"}
A = (TypeA) (A | B);
```

The left-hand operand is evaluated exactly once.

## Behavior by Operand Type

### 1. Integral Types (`byte`, `short`, `int`, `long`, `char`)

When applied to integer types, `|=` performs a bitwise inclusive OR operation. The JVM compares the binary representations of both operands bit by bit. If either corresponding bit is `1`, the resulting bit is `1`. If both bits are `0`, the resulting bit is `0`.

```java theme={"dark"}
int a = 5;      // Binary: 0101
a |= 3;         // Binary: 0011
// Result in a: 7 (Binary: 0111)
```

### 2. Boolean Type

When applied to `boolean` variables, `|=` performs a logical inclusive OR operation. If either the left or right operand is `true`, the left operand is assigned `true`.

Unlike the short-circuit logical OR operator (`||`), the underlying `|` operator strictly evaluates both operands before performing the assignment.

```java theme={"dark"}
boolean flag = false;
flag |= true; 
// Result in flag: true
```

## Implicit Type Casting

A critical mechanical feature of the `|=` operator (and all compound assignment operators in Java) is that it automatically performs an implicit narrowing primitive conversion if the result of the OR operation is wider than the left operand's type.

When performing bitwise operations on types smaller than `int` (like `byte` or `short`), Java automatically promotes the operands to `int` before the operation. The `|=` operator handles the mandatory downcast back to the original type automatically.

```java theme={"dark"}
byte b = 10;
// b = b | 5; // Compilation error: incompatible types (int cannot be converted to byte)
b |= 5;       // Compiles successfully. Equivalent to: b = (byte) (b | 5);
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
