public interface MyAutoService { void performAction(); } @AutoService(MyAutoService.class) public class MyAutoServiceImpl implements MyAutoService { @Override public void performAction() { } } public class Main { public static void main(String[] args) { AutoServiceLoader<MyAutoService> loader = new AutoServiceLoader<>(MyAutoService.class); List<MyAutoService> services = loader.loadServices(); for (MyAutoService service : services) { service.performAction(); } } }


上一篇:
下一篇:
切换中文