I have some old (pre java 6) code that depends on the sun.misc.Service
API, such as:
sun.misc.Service.providers(MyServiceProvider.class);
This class is being removed (not just internalized) in Java 9.
What alternate Java SE API can I use?
The sun.misc.Service
class has been replaced by java.util.ServiceLoader
in Java 6.
The following code examples are equivalent:
Before
Iterator<MyServiceProvider> = sun.misc.Service.providers(MyServiceProvider.class);
After
Iterator<MyServiceProvider> = java.util.ServiceLoader.load(MyServiceProvider.class).iterator();
As those in comments have pointed out, java.util.ServiceLoader has been around for a long time (Java 6).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With