To tell the truth I didn’t use ServiceLoader.Provider. Please, consider the
following code:
module msg.service.provider.swing {
......
provides service.api.AService with service.provider.TheServiceProvider;
...
}
...
public class TheServiceProvider {
public static AService provider() {
return new AServiceImpl(); <-- This is a service instance.
}
}
…
ServiceLoader<AService> sl = ServiceLoader.load(AService.class);
Stream<ServiceLoader.Provider<AService>> stream = sl.stream();
Do I understand it correctly, that the instance (we have only one provider in
this ex) of ServiceLoader.Provider will be created on the base of the
information taken from TheServiceProvider.provider() method using reflection?
--
Best regards, Alex Orlov
>Понедельник, 23 ноября 2020, 11:47 +03:00 от Alan Bateman
><alan.bate...@oracle.com>:
>
>On 23/11/2020 08:28, Alex Orlov wrote:
>>
>> I don’t agree with that. It returns the object that is an instance of the
>> service.
>> The method returns an instance of the service provider.
>
>The enhancements to ServiceLoader in Java 9 were tracked as
>#ServiceLoaderEnhancements [1], the link to "Proposal" has a good
>summary of the update.
>
>-Alan
>
>
>[1]
>https://openjdk.java.net/projects/jigsaw/spec/issues/#ServiceLoaderEnhancements