Merge pull request #9370 from mangstadt/patch-1
Use ServiceLoader class to obtain service instance
This commit is contained in:
commit
23ea65bee8
@ -1,12 +1,15 @@
|
|||||||
package com.baeldung.modules.main;
|
package com.baeldung.modules.main;
|
||||||
|
|
||||||
|
import com.baeldung.modules.hello.HelloInterface;
|
||||||
import com.baeldung.modules.hello.HelloModules;
|
import com.baeldung.modules.hello.HelloModules;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
public class MainApp {
|
public class MainApp {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HelloModules.doSomething();
|
HelloModules.doSomething();
|
||||||
|
|
||||||
HelloModules module = new HelloModules();
|
Iterable<HelloInterface> services = ServiceLoader.load(HelloInterface.class);
|
||||||
module.sayHello();
|
HelloInterface service = services.iterator().next();
|
||||||
|
service.sayHello();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user