Java exports Keyword
Example
Use exports
in a module's module-info.java file:
module mymodule {
exports com.w3schools.package1;
exports com.w3Schools.package2 to module1, module2;
}
Definition and Usage
The exports
keyword allows a package from a module to be used by other modules.
If the to
keyword is added, the exported package is only allowed to be used by the modules that are listed.
Note: The exports
keyword is a module directive meant to be used in the module-info.java file of a module.
The exports
keyword was new in Java 9.