I am working on a java-library and due to information-hiding, I was forced to move all my java-files into a single package in order to mark some of them as package private.
Is there any way to some how organize these java-files into "packages" without violating the information-hiding-principle?
That is what Java 9 modules are for. They introduce an additional level of encapsulation.
module-private
are public members in packages which are not exported.In the following example, class
PublicClass
is in packagecom.library
. In that same package, there is amodule-info.java
file which declares a Java module and exports packages which are public API. All classes in the packages which are not exported will not be visible from modules which depend on this one.