> ## 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.

# Kotlin Referential Equality

The `===` operator evaluates referential equality in Kotlin. It returns `true` if and only if two references point to the exact same object instance in memory. Its negated counterpart is `!==`, which returns `true` if two references point to different memory addresses.

```kotlin theme={"dark"}
val referenceA = Any()
val referenceB = referenceA
val referenceC = Any()

val isSameReference = referenceA === referenceB      // true
val isDifferentReference = referenceA !== referenceC // true
```

## Mechanical Behavior

The behavior of `===` depends strictly on how the Kotlin compiler represents the underlying types on the target platform (such as the JVM).

### 1. Reference Types (Objects)

For standard classes and objects, `===` compares the memory addresses of the references. It bypasses the `equals()` method entirely. Even if two distinct objects contain identical data, `===` will evaluate to `false` because they occupy different memory allocations.

```kotlin theme={"dark"}
class Node(val value: Int)

val node1 = Node(10)
val node2 = Node(10)
val node3 = node1

val check1 = node1 === node2 // false: Different memory addresses
val check2 = node1 === node3 // true: Same memory address
```

### 2. Primitive Types

Kotlin abstracts primitive types (like `Int`, `Double`, `Boolean`), but at runtime on the JVM, non-nullable representations of these types are compiled down to Java primitives (e.g., `int`, `double`). Because JVM primitives do not have memory identities distinct from their values, using the referential equality operator (`===`) on non-nullable primitive types is deprecated in modern Kotlin. The compiler explicitly warns against this (`Identity equality for arguments of types Int and Int is deprecated`) because the operation is meaningless and evaluates identically to structural equality.

```kotlin theme={"dark"}
val x: Int = 1000
val y: Int = 1000

// Deprecated: Identity equality for arguments of types Int and Int is deprecated
val check = x === y 
```

### 3. Boxed Types (Nullable Primitives)

When a primitive type is marked as nullable (e.g., `Int?`), the Kotlin compiler boxes the value into a reference type (e.g., `java.lang.Integer`). When applying `===` to boxed types, referential equality is enforced. This can lead to differing results based on JVM memory caching mechanisms (like the Integer cache for values between -128 and 127).

```kotlin theme={"dark"}
val a: Int? = 1000
val b: Int? = 1000
val c: Int? = 10
val d: Int? = 10

val checkBoxed1 = a === b // false: Different boxed object references (outside cache range)
val checkBoxed2 = c === d // true: Same reference due to JVM Integer caching
```

## Contrast with Structural Equality (`==`)

To understand `===` mechanically, it must be contrasted with `==`.

* The `==` operator evaluates **structural equality**. It is translated by the compiler to a null-safe invocation of the `equals()` method: `a?.equals(b) ?: (b === null)`.
* The `===` operator evaluates **referential equality**. It never invokes `equals()` and strictly compares the pointer/reference value.

<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 Kotlin 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>
