@Test public void singletonAnnotatedClassIsAlwaysTheSame() { Predicate<ServiceLoader.Provider<SampleService>> findSingletonProviders = p -> p.type() == SingletonSampleService.class; SampleService firstResult = sampleServiceServiceLoader.stream() .filter(findSingletonProviders) .map(ServiceLoader.Provider::get) .findAny().get(); SampleService secondResult = sampleServiceServiceLoader.stream() .filter(findSingletonProviders) .map(ServiceLoader.Provider::get) .findAny().get(); assertThat(firstResult).isSameAs(secondResult); }
public Stream<ServiceLoader.Provider<S>> stream() { return serviceLoader.stream() .map(ProviderExt::new); }
ServiceLoaderExt { public Stream<ServiceLoader.Provider<S>> stream() { return serviceLoader.stream() .map(ProviderExt::new); } }
ServiceLoaderExt { public Stream<ServiceLoader.Provider<S>> stream() { return serviceLoader.stream() .map(ProviderExt::new); } private  ServiceLoaderExt(ServiceLoader<S> serviceLoader); }
ServiceLoaderExt { public Stream<ServiceLoader.Provider<S>> stream() { return serviceLoader.stream() .map(ProviderExt::new); } private  ServiceLoaderExt(ServiceLoader<S> serviceLoader); static ServiceLoaderExt<S> load(Class<S> service, ClassLoader loader); static ServiceLoaderExt<S> load(Class<S> service); static ServiceLoaderExt<S> loadInstalled(Class<S> service); static ServiceLoaderExt<S> load(ModuleLayer layer, Class<S> service); Optional<S> findFirst(); void reload(); void forEach(Consumer<? super S> action); Spliterator<S> spliterator(); Iterator<S> iterator(); Stream<ServiceLoader.Provider<S>> stream(); }
ServiceLoaderExt { public Stream<ServiceLoader.Provider<S>> stream() { return serviceLoader.stream() .map(ProviderExt::new); } private  ServiceLoaderExt(ServiceLoader<S> serviceLoader); static ServiceLoaderExt<S> load(Class<S> service, ClassLoader loader); static ServiceLoaderExt<S> load(Class<S> service); static ServiceLoaderExt<S> loadInstalled(Class<S> service); static ServiceLoaderExt<S> load(ModuleLayer layer, Class<S> service); Optional<S> findFirst(); void reload(); void forEach(Consumer<? super S> action); Spliterator<S> spliterator(); Iterator<S> iterator(); Stream<ServiceLoader.Provider<S>> stream();  }