The main goal of this project is to explore basic features of
modularity
introduced in Java 9
:
- exports
- exports
X
toY
- requires
- requires transitive
- open module
Reference: Java 9 Modularity
-
moduleA, moduleB, moduleC - exploring
exports
,exports X to Y
,requires
,requires transitive
. -
openModule, ordinaryModule, reflection - exporing
open module
and correlatemodularity
withreflection
.
Assume that we analyze module-info.java
under module X
- exports
Y
- exporting packageY
. - exports
Y
toZ
(Qualified Export
) - export packageY
to moduleZ
.
In general, we should avoid usingqualified exports
between modules in an application. - requires
Y
- indicates a dependency on the moduleY
.
Remember that the moduleY
has to be also added to dependencies ofX
(directly to module path or topom.xml
). - requires transitive
Y
- requiring automatically all modules required byY
. - open module - all its types are available for
deep reflection
(break into private parts of types atrun-time
) by other modules, while strong encapsulation is still upheld at compile-time. This property holds regardless of whether any packages are exported.
Deep reflection
is used by many libraries. For example,Spring
orHibernate
inject values into nonpublic fields of classes.