Return to site

JPMS: 'Qualilfied' dependencies


· java

An exports…to directive enables you to specify in a comma-separated list precisely which module’s or modules’ code can access the exported package—this is known as a qualified export.

Golden rule: Export packages, but require modules.
This means that exporting is always done at the package level,
so all public classes within the package are exported as one block.
You can't pick which public classes within that exported package are visible.
You may only want some of the public classes to be accessible by foreign modules.
You can always hide classes by making them package private,
but this would also make them invisible to other packages in the same module that might need them.
A Qualified export is the exporting of packages to chosen modules.
Think of them as a white listing approach to exporting.
Qualified exports allow the exporting module to choose which foreign modules are allowed to read it.
It acts as a fine-grained filter, giving individual access at the package level.


I can add as many modules to the exports as I want, separated by commas.

Transitivity still works with qualified export.