com.fireflysource.common.service.ServiceUtils Maven / Gradle / Ivy
package com.fireflysource.common.service;
import java.util.ServiceLoader;
/**
* @author Pengtao Qiu
*/
abstract public class ServiceUtils {
public static T loadService(Class clazz, T defaultService) {
T service = null;
ServiceLoader serviceLoader = ServiceLoader.load(clazz);
for (T t : serviceLoader) {
service = t;
}
if (service == null) {
service = defaultService;
}
return service;
}
}