io.quarkiverse.operatorsdk.common.ClassLoadingUtils Maven / Gradle / Ivy
package io.quarkiverse.operatorsdk.common;
import java.lang.reflect.InvocationTargetException;
public class ClassLoadingUtils {
private ClassLoadingUtils() {
}
@SuppressWarnings({ "unchecked", "unused" })
public static Class loadClass(String className, Class expected) {
try {
return (Class) Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (Exception e) {
throw new IllegalArgumentException("Couldn't find class " + className, e);
}
}
public static T instantiate(Class toInstantiate) {
try {
final var constructor = toInstantiate.getConstructor();
constructor.setAccessible(true);
return constructor.newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalArgumentException("Couldn't instantiate " + toInstantiate.getName(),
e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy