I'm trying to use best practices that fit with Java 9 module system so that I have less work to do to get the benefits (and our system right now could really benefit from some modularity).
Is it permissible under the current standard for module A to export the package com.example.foo and also for module B to export the package com.example.foo?
As a related question, if relevant, is whether this point is actually settled or if it's still not final.
According to the latest State of the Module System, the module system ensures that "every module reads at most one module defining a given package, and that modules defining identically-named packages do not interfere with each other." And: "When code in a module refers to a type in a package then that package is guaranteed to be defined either in that module or in precisely one of the modules read by that module."
This means that two different modules may export the same package if - at build time and at run time - no module depends on both A and B at the same time and if A and B don't depend on each other. In theory you could have two modules that export the same package, and use them one at a time with another depending module.
I would also suggest, as has already been suggested, that it is best practice to have a package exported by a single module instead of two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With