A star import (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.
*) is a compile-time namespace directive that introduces all accessible declarations from a specified package or classifier (class, interface, enum, or object) into the current file’s lexical scope.
By appending an asterisk to an import path, the Kotlin compiler is instructed to perform on-demand symbol resolution for any unaliased and unqualified references found within the file.
Syntax
Star imports are declared at the top of a Kotlin file, immediately following thepackage declaration.
Compiler Mechanics and Resolution
1. On-Demand Linking Star imports do not bloat the compiled bytecode or increase memory footprint at runtime. They are strictly a frontend compiler mechanism. The compiler scans the wildcard paths only to resolve symbols explicitly referenced in the source code. The resulting.class files contain exact, fully qualified references identical to those generated by explicit single-symbol imports.
2. Precedence and Shadowing
Kotlin’s symbol resolution hierarchy dictates that explicit imports take precedence over star imports. If a file contains both a star import and an explicit import for a symbol with the same name, the explicit import shadows the star import.
Classifier Star Imports
Unlike Java, which restricts wildcard imports to packages and requires a separateimport static syntax for class members, Kotlin unifies this behavior. Applying a star import to a classifier exposes its nested types, enum constants, static members, and members of its Companion object directly to the file’s scope.
Implicit Star Imports
The Kotlin compiler automatically injects a default set of star imports into every.kt file during the compilation phase. This provides immediate access to the standard library without explicit declarations. The default implicit imports include:
kotlin.*kotlin.annotation.*kotlin.collections.*kotlin.comparisons.*kotlin.io.*kotlin.ranges.*kotlin.sequences.*kotlin.text.*
Master Kotlin with Deep Grasping Methodology!Learn More





