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.
Nothing is a special type in Kotlin that represents a value that never exists. In type theory, it is known as the bottom type, meaning it is a strict subtype of every other type in the Kotlin type system, including both nullable and non-nullable types. Because it has no instances, an expression of type Nothing indicates to the compiler that code execution will never successfully terminate or return from that specific path.
Structural Definition
In the Kotlin standard library,Nothing is defined as a class with a private constructor, making instantiation impossible:
Type System Hierarchy
As the bottom type,Nothing sits at the exact opposite end of the type hierarchy from Any? (the top type).
Nothing is a subtype of all types, an expression evaluating to Nothing satisfies the type requirements of any variable or function return. The compiler safely permits this because it knows the assignment will never actually occur at runtime.
Interaction with Covariant Generics
The fact thatNothing is a subtype of all types makes it highly valuable in Kotlin’s implementation of covariant generics. When a generic type parameter is declared as covariant using the out modifier (e.g., interface List<out E>), a type parameterized with Nothing becomes a valid subtype of that generic parameterized with any other type.
The Kotlin standard library utilizes this property for the internal singleton object that backs the emptyList() function. This internal object (named EmptyList) implements List<Nothing>. Because List is covariant, List<Nothing> is a valid subtype of List<String>, List<Int>, or any other typed list. This allows the exact same singleton instance to be safely returned by the generic emptyList<T>() function regardless of the inferred type T.
Control Flow and Reachability Analysis
The Kotlin compiler utilizesNothing for static analysis, specifically for reachability and control flow. When a function’s return type is explicitly declared as Nothing, the compiler guarantees that the function will not return normally (e.g., it always throws an exception or enters an infinite loop).
Consequently, the compiler marks any code sequentially following a Nothing expression as unreachable dead code.
TODO() is the most common built-in application of this mechanism. It explicitly declares a Nothing return type by throwing a NotImplementedError. This satisfies the compiler’s strict return type requirements during active development while preventing execution from proceeding past the incomplete code.
Nothing vs. Unit
Developers often confuse Nothing with Unit (Kotlin’s equivalent to void). They represent fundamentally different concepts in the type system:
Unit: Represents a function that successfully completes but does not return meaningful data. It has exactly one instance (theUnitobject).Nothing: Represents a function or expression that never completes normally. It has zero instances.
Nothing? (Nullable Nothing)
While Nothing has zero instances, its nullable counterpart, Nothing?, has exactly one valid instance: null. Nothing? acts as the bottom type for all nullable types in Kotlin. When a variable is initialized with null and no explicit type is provided, the compiler infers its type as Nothing?.
Master Kotlin with Deep Grasping Methodology!Learn More





