Modules
suggest changeVersions
Java SE 9. The requires public form below is early-access syntax; the directive that shipped is requires transitive.
Syntax
- requires java.xml;
- requires public java.xml; # exposes module to dependents for use
- exports com.example.foo; # dependents can use public types in this package
- exports com.example.foo.impl to com.example.bar; # restrict usage to a module
Remarks
The use of modules is encouraged but not required. This allows existing code to continue working in Java 9. It also allows for a gradual transition to modular code.
Code that is not in a named module is placed in the unnamed module when it is compiled and when it runs. This module can use types from every other module, but only from packages that have an exports declaration.
All packages in the unnamed module are exported automatically.
Keywords, e.g. module, are restricted inside the module declaration but can continue to be used as identifiers elsewhere.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents