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 is Kotlin’s negated runtime type-checking operator. It evaluates to true if an object is not an instance of a specified type, and false if it is. While it is logically equivalent to applying the unary logical NOT operator to a parenthesized standard type-check (!(expression is Type)), !is is syntactically distinct and functions as a dedicated binary operator in Kotlin’s grammar.
Syntax
Technical Mechanics
Runtime Type Identification (RTTI) The operator relies on RTTI to inspect the actual runtime class of the object referenced by theexpression. It does not evaluate the static (compile-time) type of the variable, but rather the instance it points to in memory.
Nullability Rules
The !is operator inherently handles nullability based on the right-hand type declaration:
- If the target
Typeis non-nullable (e.g.,String), evaluatingnull !is Stringreturnstrue. - If the target
Typeis nullable (e.g.,String?), evaluatingnull !is String?returnsfalse, becausenullis considered a valid instance of any nullable type.
!is is subject to generic type erasure. Generally, you cannot use !is to check against a specific generic instantiation at runtime, requiring the use of star-projected types instead.
!is can evaluate generic type arguments:
- Reified Type Parameters: When used inside an
inlinefunction against areifiedtype parameter, as the type is preserved at the call site. - Statically Known Type Arguments: When the type arguments of the expression are already statically known by the compiler (e.g., evaluating
collection !is List<String>whencollectionis statically typed asCollection<String>). - Arrays:
Arraytypes retain their generic type parameters at runtime, allowing checks likeobj !is Array<String>.
Control-Flow Analysis and Smart Casting
The Kotlin compiler’s control-flow analysis engine heavily utilizes the!is operator to perform smart casting. While the is operator typically smart-casts within the bounds of a conditional block, !is is used to trigger smart casting for the remainder of a scope via early exits (such as return or throw).
If the compiler detects that execution only continues when !is evaluates to false, it automatically safely casts the variable to the target type for all subsequent instructions in that scope.
Master Kotlin with Deep Grasping Methodology!Learn More





