package tschipp.carryon.platform; import tschipp.carryon.Constants; import tschipp.carryon.platform.services.IGamestagePlatformHelper; import tschipp.carryon.platform.services.IPlatformHelper; import java.util.ServiceLoader; public class Services { public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); public static final IGamestagePlatformHelper GAMESTAGES = load(IGamestagePlatformHelper.class); public static T load(Class clazz) { final T loadedService = ServiceLoader.load(clazz) .findFirst() .orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName())); Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz); return loadedService; } }