ServiceLoader
The java.util class that finds implementations of a service interface at run time.
In more detail
A consumer module declares uses for the interface and calls ServiceLoader.load. A provider module declares provides Interface with Implementation. A named consumer without a uses directive gets a ServiceConfigurationError.
Example
for (Pricing p : ServiceLoader.load(Pricing.class)) { ... }Related terms
- module — A named set of packages with a descriptor, module-info.java, that declares what it requires, exports, opens, uses and provides.
Taught in
- Modules: Exports, Opens And Services — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep