TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
=== 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.
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.
2. Primitive Types
Kotlin abstracts primitive types (likeInt, 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.
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).
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 theequals()method:a?.equals(b) ?: (b === null). - The
===operator evaluates referential equality. It never invokesequals()and strictly compares the pointer/reference value.
Master Kotlin with Deep Grasping Methodology!Learn More





