List of utility methods to do Reflection Constructor Invoke
T | invokeConstructor(Constructor invoke Constructor try { return constructor.newInstance(parameters); } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { throw new IllegalStateException(ex); |
T | invokeConstructor(final Class Invokes a constructor. assert paramTypes.length == args.length; @Nullable T obj = null; try { if (paramTypes.length > 0) { final Constructor<T> constructor = clazz.getConstructor(paramTypes); obj = constructor.newInstance(args); } else { ... |
Object | invokeConstructor(final Constructor constructor, final Object... args) Invoke the specified Constructor with the supplied arguments. if (constructor == null) { throw new IllegalArgumentException("Constructor must not be null."); constructor.setAccessible(true); return constructor.newInstance(args); |
Object | invokeConstructor(final Constructor constructor, final Object[] args) Construct an object with the given Constructor and the given array of arguments. return constructor.newInstance(args);
|
T | invokeConstructor(final Constructor extends T> constructor, final Object... args) invoke Constructor try { final T object = constructor.newInstance(args); return object; } catch (final RuntimeException e) { throw e; } catch (final Error e) { throw e; } catch (final InvocationTargetException e) { ... |
Object | invokeConstructor(String className, Class>[] paramTypes, Object[] paramValues) Invokes constructor in class by given className , paramTypes and paramValues . Class<?> clazz = Class.forName(className);
Constructor<?> constructor = clazz.getConstructor(paramTypes);
return constructor.newInstance(paramValues);
|
Object | invokeConstructor(String className, Object... arguments) Returns an instantiation of the class specified by the input String using the arguments provided. try { Class<?> cls = Class.forName(className); Class<?>[] parameterTypes = new Class<?>[arguments.length]; int i = 0; for (Object argument : arguments) parameterTypes[i++] = argument.getClass(); Constructor<?> constructor = cls.getConstructor(parameterTypes); if (!constructor.isAccessible()) ... |
T | invokeConstructorOrFail(Constructor Invokes the given constructor with optional arguments args , returning the new instance created by constructor . try { return constructor.newInstance(args); } catch (InvocationTargetException e) { throw new RuntimeException("Failed to call constructor '" + constructor.getDeclaringClass().getSimpleName() + "': " + e.getCause().getMessage(), e.getCause()); } catch (Exception e) { throw new RuntimeException("Failed to call constructor '" ... |
Object | invokeCtor(Constructor ctor, String str) invoke Ctor try { return ctor.newInstance(new Object[] { str }); } catch (Throwable t) { return null; |
Object | invokeExactConstructor(Class klass, Object arg) Convenience method returning new instance of Object[] args = { arg };
return invokeExactConstructor(klass, args);
|