Skip to main content

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.

A star import (*) 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 the package declaration.
// Imports all top-level declarations (classes, functions, properties) from a package
import java.util.*

// Imports all nested declarations (enum constants, companion object members, static members) from a classifier
import java.time.DayOfWeek.*

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.
import java.util.*        // Introduces java.util.Date
import java.sql.Date      // Explicit import takes precedence

// Resolves to java.sql.Date (requires a Long timestamp parameter)
val date: Date = Date(System.currentTimeMillis())
3. Namespace Collisions If multiple star imports introduce identically named symbols, and that symbol is referenced in the code, the compiler cannot infer the intended target. This results in an ambiguous reference compilation error. The collision must be resolved by adding an explicit import for the desired symbol.
import java.util.*        // Contains 'Date'
import java.sql.*         // Contains 'Date'

// Error: Unresolved reference: Date (Ambiguity)
// Resolution requires: import java.util.Date OR import java.sql.Date

Classifier Star Imports

Unlike Java, which restricts wildcard imports to packages and requires a separate import 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.
import java.lang.Math.*

val radius = 5.0
// PI and cos() are resolved via the java.lang.Math.* classifier star import
val x = PI * cos(radius) 

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