public static <T> T getService(final Class<T> intf, final Class<? extends T> defaultImpl)
        throws ModuleLoaderException
    {
        final T implementation = getServiceOrElse(intf, null);

        if (implementation != null) {
            return implementation;
        }

        if (defaultImpl == null) {
            throw new ModuleLoaderException("Missing implementation: " + intf);
        }

        try {
            return defaultImpl.getConstructor().newInstance();
        } catch (final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new ModuleLoaderException("Cannot instantiate class", e);
        }
    }
public static <T> T getService(final Class<T> intf, final Class<? extends T> defaultImpl)
        throws ModuleLoaderException
    {
        final T implementation = getServiceOrElse(intf, null);

        if (implementation != null) {
            return implementation;
        }

        if (defaultImpl == null) {
            throw new ModuleLoaderException("Missing implementation: " + intf);
        }

        try {
            return defaultImpl.getConstructor().newInstance();
        } catch (final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new ModuleLoaderException("Cannot instantiate class", e);
        }
    }
public static < T > T getService ( final Class < T > intf , final Class < ? extends T > defaultImpl ) throws ModuleLoaderException { final T implementation = getServiceOrElse ( intf , null ) ; if ( implementation != null ) { return implementation ; } if ( defaultImpl == null ) { throw new ModuleLoaderException ( "Missing implementation: " + intf ) ; } try { return defaultImpl . getConstructor ( ) . newInstance ( ) ; } catch ( final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) { throw new ModuleLoaderException ( "Cannot instantiate class" , e ) ; } }
Determine the first advertised service implementation for the specified interface. The implementations are advertised via the Java
"ServiceLoader" mechanism.

@param intf the interface to find an advertised service implementation for
@param defaultImpl the default implementation class if an advertised one is not found, may be null
@param <T> the interface
@return an advertised implementation of intf of type T
@throws ModuleLoaderException if the implementation is missing and no defaultImpl is specified
Determine the first advertised service implementation for the specified interface . The implementations are advertised via the Java ServiceLoader mechanism .