Lets say, I write a module/library named mylib
that uses an internal/hidden third party module/library named internal
. The API of mylib does not expose any functionality from that third party library and it may be replaced by something else in the near future.
module mylib {
requires internal;
exports some.pgk.from.mylib;
}
But here is my problem. The internal library needs reflective access to the classes/objects that are passed through the public API of mylib to do it's work.
An example application/module named app
that utilizes my library would have to define the following moduleinfo.java
module app {
requires mylib;
opens some.pkg.from.app to internal;
}
But this is bad, because it exposes the internally used module to the users of my library, and I would not be able to remove/change it in the future without breaking app. Ideally i would like to allow the module internal reflective access to all modules that are open to mylib instead:
module app {
requires mylib;
opens some.pkg.from.app to mylib; // also open to internal without naming it
}
Can this be done with the current (Java 17) module system? Is there a good workaround in case this is not possible?
Aucun commentaire:
Enregistrer un commentaire