Kotlin provides an import aliasing mechanism via 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.
as keyword, allowing developers to locally bind a new identifier to a fully qualified class, function, property, or object at the point of import. This creates a file-scoped alternative identifier for the imported declaration without altering the original source code.
Syntax
The aliasing syntax appends theas keyword followed by the desired local identifier to a standard import directive:
Technical Mechanics
- Lexical Scoping: An import alias is strictly confined to the file in which it is declared. It does not pollute the global namespace or affect how the target declaration is referenced in other files within the same module.
- Compiler Resolution: The alias is a purely syntactic construct handled during the compiler’s import resolution phase. The Kotlin compiler maps the
LocalAliasdirectly to theOriginalIdentifier’s fully qualified name. It does not generate wrapper classes or incur runtime overhead. - Applicability: The
askeyword can be applied to any importable symbol. This includes:- Classes and Interfaces
- Top-level functions
- Top-level properties
- Object declarations
- Enum constants
Code Examples
Aliasing ClassesDistinction from typealias
It is critical to distinguish an import alias (import ... as) from a type alias (typealias):
| Characteristic | import ... as | typealias |
|---|---|---|
| Scope | File-level only. | Package, module, or public scope (based on visibility modifiers). |
| Target | Any importable symbol (Types, Functions, Properties, Objects). | Types only (Classes, Interfaces, Function Types). |
| Declaration Location | File header, alongside standard imports. | Top-level declaration within a file. |
| Reusability | Cannot be referenced outside the declaring file. | Can be imported and used by other files/modules. |
Master Kotlin with Deep Grasping Methodology!Learn More





