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.
is operator evaluates whether an object is an instance of a specified type at runtime. It performs runtime type identification (RTTI) and returns a Boolean. Its negated counterpart, !is, returns true if the object is not an instance of the specified type.
Compiler Mechanics
Smart Casting When anis check evaluates to true, the Kotlin compiler performs data-flow analysis. If the compiler can guarantee that the variable will not be modified between the check and its subsequent usage, it automatically applies a smart cast. Within the scope where the condition holds true, the variable is treated as the target type, eliminating the need for the explicit cast operator (as).
when Expressions
The is operator is natively integrated into when expressions as a branch condition. This provides an idiomatic mechanism for multi-way type checking and smart casting without requiring explicit if-else chains.
is operator strictly adheres to Kotlin’s type system regarding nullability.
- Checking against a non-nullable type (
is Type) implicitly acts as a null check. If the operand isnull, the expression evaluates tofalse. - Checking against a nullable type (
is Type?) evaluates totrueif the operand isnull, becausenullis a valid instance ofType?.
JVM Type Erasure Limitations
Because Kotlin compiles to the JVM (in its primary target), generic type arguments are generally erased at runtime. Consequently, theis operator cannot evaluate parameterized types with specific type arguments by default.
To perform type checks on generic collections or classes, you must use star-projected types (*), which verify the base class but not the generic payload.
is operator to evaluate exact generic type arguments:
- Reified Type Parameters: When using
inlinefunctions withreifiedtype parameters, the compiler inlines the actual type at the call site, preserving the type information at runtime. - Arrays: Arrays in Kotlin are reified on the JVM. They retain their component types at runtime, allowing direct type checks against specific array types.
- Statically Known Type Arguments: If the compiler’s static type checking already guarantees the generic type argument based on the variable’s declaration, it permits an
ischeck on the base class.
Master Kotlin with Deep Grasping Methodology!Learn More





