static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }