Thursday 7 January 2021

Java9: Qualified Exports: Export to specific modules

In my previous posts, I explained how a module expose packages to other modules using ‘exports’ keyword.

 

There are cases, where you want to expose packages to specific modules. You can do this by using qualified exports in module descriptor.

 

Syntax

module {module_name} {
  ...
  exports {package} to {module_name}, {module_name}....
  ...
}

 

Example

module M1{
	...
	exports com.sample.app.util to M2, M3
	...
}

 

In the example, the package 'com.sample.app.util' is exposed to modules M2 and M3 only.

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment