A package declaration in Kotlin establishes the namespace for the contents of a source file, dictating the fully qualified name (FQN) of all classes, interfaces, functions, and properties defined within it.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.
Technical Characteristics
Placement and Syntax Thepackage directive must be placed at the top of a Kotlin source file (.kt), immediately following any file-level annotations (such as @file:JvmName(...) or @file:OptIn(...)). It must strictly precede all import directives and top-level declarations.
Visibility and Access Control
In Kotlin, packages are strictly used for namespacing and code organization; they do not provide encapsulation or access control. Unlike Java, Kotlin does not have “package-private” visibility, and packages do not dictate visibility boundaries. Access control is instead managed via visibility modifiers (private, protected, internal, public), where internal restricts visibility to the compilation module, completely independent of the package structure.
File System Decoupling
Kotlin does not enforce a strict mapping between the declared package name and the underlying directory structure. A file containing package org.example.network can technically reside in any directory path (e.g., src/main/kotlin/utils/). However, aligning the directory structure with the package name remains the standard convention for Java interoperability and project navigation.
Default Package
If a Kotlin source file omits the package declaration, all top-level declarations within that file are automatically assigned to the default, unnamed package.
Namespace Scope
The package declaration applies to all top-level constructs in the file, including variables and functions, rather than being limited to classes.
Master Kotlin with Deep Grasping Methodology!Learn More





