Class ServiceHelper

    • Method Detail

      • singleton

        public static final <S> S singleton​(ServiceLoader<S> serviceLoader)
        Type Parameters:
        S - type of the service.
        Parameters:
        serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
        Returns:
        the requested service.
      • singleton

        public static final <S> S singleton​(ServiceLoader<S> serviceLoader,
                                            boolean unique)
        Type Parameters:
        S - type of the service.
        Parameters:
        unique - - true if an exception is thrown if the service is not unique, false otherwise (allow overriding default).
        serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
        Returns:
        the requested service.