All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.tests.snippets.ServiceLoading Maven / Gradle / Ivy

package org.qbicc.tests.snippets;

import java.util.ServiceLoader;

public class ServiceLoading {
    public interface MyService {
        int value();
    }

    public static class MyImpl1 implements  MyService {
        public int value() {
            return 100;
        }
    }

    public static class MyImpl2 implements  MyService {
        public int value() {
            return 10;
        }
    }

    public static void main(String[] args) {
        int sum = 0;
        for (MyService s: ServiceLoader.load(MyService.class)) {
            sum += s.value();
        }
        System.out.print(sum);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy