I'm curious about JDK9 modules. Let's say you have the following 3 packages:
com.company.product com.company.product.impl_a com.company.product.impl_b
Classes in product.impl_a and product.impl_b packages can only be accessed by classes in product package. The user should use only classes from the product package. You can imagine that passing certain flags or properties will determine whether impl_a or impl_b will be used internally.
In JDK8- you must make these classes inside impl_a and impl_b public . This sucks because users can be tricked into using these classes. This is perfectly acceptable and permitted.
How can JDK9 help here? We will declare a module for product.impl_a and one more for product.impl_b and declare that the exported classes should be accessible only to the third module product , which will depend on the two modules product.impl_a and product.impl_b ? Also, would it be impossible to declare a new module that will depend on product.impl_a or product.impl_b ? Can other modules depend only on the product module?
source share