Java extensibility and JPMS (ServiceLoader)

Alex Buckley alex.buckley at oracle.com
Mon Jan 22 20:13:39 UTC 2024


Tomas,

A clarification for point 3:

On 1/19/2024 5:02 AM, Tomas Langer wrote:
> *Ad 3 - Provider implementation must be public with public constructor*
> -------------------------------------
> Details:
> Provider implementations are not supposed to be visible to users - they 
> are not public API of my module (the fact that I provide a service is 
> part of my public API).
> Right now there is only one option to work around this, and it only 
> works in JPMS, and in my opinion it brings in even more problems - put 
> the provider implementation in an un-exported package.
> The problem with this approach is that now the provider implementation 
> MUST use only public methods of my module, thus creating even more 
> public APIs, where if I just put it in my exported package, I can use 
> package private methods of my other classes to implement the service (so 
> I pay the price of having one public class with one public constructor 
> agains multiple public classes and public methods). Also the "hiding" in 
> unexported package is lost when on classpath anyway...

I don't understand what you mean by "the provider implementation MUST 
use only public methods of my module". You have an arrangement of 
modules and packages in mind that I simply cannot see -- please share it.

Alex


More information about the jigsaw-dev mailing list