Module is a combination of code and data, it has a name and is declared to other modules A dependency module that exports a package containing public types accessible outside the module and specifies the services it uses or the service implementations it provides. All of this is specified in the module-info.java file, which is included in the module's root directory.
There are two types of "export" clauses that can be used in the "module-info.java" file.
1) Export
We need to allow other modules to use the classes and interfaces of the package tp.com.tutorialspoint.model, we can write like this:
<strong>module com.tutorialspoint.model { exports tp.com.tutorialspoint.model; }</strong>
Understand that a package can only appear in This is very important in a module. Otherwise, we will get an error like this:
<strong>Error:(1, 1) java: package exists in another module:</strong>
2) Export
<strong>module com.tutorialspoint.model { exports tp.com.tutorialspoint.model to com.tutorialspoint.gui; }</strong>
The above is the detailed content of What is the purpose of 'export' clause in module-info file in Java 9?. For more information, please follow other related articles on the PHP Chinese website!