util-moduleloader/src/main/java/com/hpe/caf/util/ModuleLoader.java
public static <T> T getServiceOrElse(final Class<T> intf, final T defaultObj)
    {
        Objects.requireNonNull(intf);
        final T ret;
        List<T> implementations = getServices(intf);
        if (implementations.isEmpty()) {
            return defaultObj;
        } else {
            ret = implementations.get(0);
        }

        if (implementations.size() > 1) {
            LOG.warn("There is more than one implementation of {} available on the classpath, taking the first available", intf);
        }
        LOG.info("Detected component implementation {}", ret.getClass().getSimpleName());
        return ret;
    }
public static <T> T getServiceOrElse(final Class<T> intf, final T defaultObj)
    {
        Objects.requireNonNull(intf);
        final T ret;
        List<T> implementations = getServices(intf);
        if (implementations.isEmpty()) {
            return defaultObj;
        } else {
            ret = implementations.get(0);
        }

        if (implementations.size() > 1) {
            LOG.warn("There is more than one implementation of {} available on the classpath, taking the first available", intf);
        }
        LOG.info("Detected component implementation {}", ret.getClass().getSimpleName());
        return ret;
    }
public static < T > T getServiceOrElse ( final Class < T > intf , final T defaultObj ) { Objects . requireNonNull ( intf ) ; final T ret ; List < T > implementations = getServices ( intf ) ; if ( implementations . isEmpty ( ) ) { return defaultObj ; } else { ret = implementations . get ( 0 ) ; } if ( implementations . size ( ) > 1 ) { LOG . warn ( "There is more than one implementation of {} available on the classpath, taking the first available" , intf ) ; } LOG . info ( "Detected component implementation {}" , ret . getClass ( ) . getSimpleName ( ) ) ; return ret ; }
Determine the first advertised service implementation for the specified interface. The implementations are advertised via the Java
"ServiceLoader" mechanism.

@param <T> the interface
@param intf the interface to find an advertised service implementation for
@param defaultObj the default object to return if an advertised one is not found, may be null
@return an advertised implementation of intf of type T, or the default object if one is not found
Determine the first advertised service implementation for the specified interface . The implementations are advertised via the Java ServiceLoader mechanism .