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.
exports directive is a statement within the Java Platform Module System (JPMS) used in a module-info.java declaration to explicitly expose a specific package to other modules. By default, all packages within a Java module are strongly encapsulated. The exports directive overrides this encapsulation, granting compile-time and runtime access to the public types residing in the specified package, as well as the public and protected members (which includes nested types) of those public types.
Unqualified Exports
An unqualifiedexports directive makes the package accessible to any module that reads the exporting module. This readability can be established directly via a requires declaration or transitively (implied readability) via a requires transitive dependency on an intermediary module.
Qualified Exports
A qualifiedexports directive restricts package visibility to a specific, comma-separated list of target modules. Modules not explicitly listed in the to clause are denied access, even if they read the exporting module.
Technical Characteristics
- Package-Level Granularity: The directive operates strictly at the package level. You cannot export individual classes or interfaces.
- Non-Transitive Sub-packages: Exporting a package does not export its sub-packages. For example,
exports com.example.core;does not exposecom.example.core.util. Each package must be exported via its own distinct directive. - Access Modifier Enforcement: The directive only crosses the module boundary. Standard Java access modifiers still apply. Package-private (default) types, as well as
privateor package-private members within an exported package, remain inaccessible to external modules. - Reflection Limitations: While
exportsallows standard reflective access topublictypes, it does not permit deep reflection (e.g., usingsetAccessible(true)to access private fields or methods) from external modules. Deep reflective access requires theopensdirective instead. - Intra-module Access: The
exportsdirective has no effect on code within the same module. All packages within a single module can freely interact with each other, subject only to standard access modifiers.
Master Java with Deep Grasping Methodology!Learn More





