> > 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. > > If module Y required module X for normal runtime operation, would not the creator of Y know this and use requires instead of requires static? Since the dependency isn't actually optional at runtime?
We're talking about a case where module Y's primary purpose is not to implement SPI from X, but to provide its own packages/functionality unrelated to X. The classes in Y that use X should not be exported, and should only be loaded when X service-loads them. Hence, the Y module will use requires static to clearly inform that the classes are required at build time, but not for Y's normal operation.