On 20/04/2023 14:55, Josiah Noel wrote:
:
if we don't export the implementation class, then the ServiceLoader becomes the only mechanism by which it can be instantiated. In this case, if the user doesn't add the optional interface dependency, it becomes impossible to accidentally load the interface and get a ClassNotFoundException when using module Y's non-SPI packages.

There could be code in the module that references the implementation class, in which case you might get NCDFE at runtime. Requires-static might be okay during initial migration of older code that is okay with dangling references and uses reflection guards. For reliability, it is usually better to use services to implement optionality.

-Alan

Reply via email to