@SuppressWarnings("unchecked") public static <T> T instantiateWithCustomCtor(String className, Class<? >[] ctorArgTypes, Object[] ctorArgs) { try { Class<? extends T> resultType = (Class<? extends T>) Class.forName(className); Constructor<? extends T> ctor = resultType.getDeclaredConstructor(ctorArgTypes); return instantiate(className, ctor, ctorArgs); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException( "Unable to find " + className, e); } catch (NoSuchMethodException e) { throw new UnsupportedOperationException( "Unable to find suitable constructor for class " + className, e); } }
public static <T> T newInstance(Class<T> type, Object... params) { return instantiate(type.getName(), findConstructor(type, params), params); }
@SuppressWarnings("unchecked") public static <T> T instantiateWithCustomCtor(String className, Class<? >[] ctorArgTypes, Object[] ctorArgs) { try { Class<? extends T> resultType = (Class<? extends T>) Class.forName(className); Constructor<? extends T> ctor = resultType.getDeclaredConstructor(ctorArgTypes); return instantiate(className, ctor, ctorArgs); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException( "Unable to find " + className, e); } catch (NoSuchMethodException e) { throw new UnsupportedOperationException( "Unable to find suitable constructor for class " + className, e); } }
@SuppressWarnings("unchecked") public static <T> T instantiateWithCustomCtor(String className, Class<? >[] ctorArgTypes, Object[] ctorArgs) { try { Class<? extends T> resultType = (Class<? extends T>) Class.forName(className); Constructor<? extends T> ctor = resultType.getDeclaredConstructor(ctorArgTypes); return instantiate(className, ctor, ctorArgs); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException( "Unable to find " + className, e); } catch (NoSuchMethodException e) { throw new UnsupportedOperationException( "Unable to find suitable constructor for class " + className, e); } }
@SuppressWarnings("unchecked") public static <T> T instantiateWithCustomCtor(String className, Class<? >[] ctorArgTypes, Object[] ctorArgs) { try { Class<? extends T> resultType = (Class<? extends T>) Class.forName(className); Constructor<? extends T> ctor = resultType.getDeclaredConstructor(ctorArgTypes); return instantiate(className, ctor, ctorArgs); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException( "Unable to find " + className, e); } catch (NoSuchMethodException e) { throw new UnsupportedOperationException( "Unable to find suitable constructor for class " + className, e); } }
public static <T> T newInstance(Class<T> type, Object... params) { return instantiate(type.getName(), findConstructor(type, params), params); }
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> type, Object... params) { return instantiate(type.getName(), findConstructor(type, params), params); }
public static <T> T newInstance(Class<T> type, Object... params) { return instantiate(type.getName(), findConstructor(type, params), params); }