List of utility methods to do Reflection Constructor Invoke
Object | invokePrivateConstructor(Class> clazz) Utility method for Unit tests to invoke private constructors Constructor<?> constructor = null; try { constructor = clazz.getDeclaredConstructor(); } catch (NoSuchMethodException e) { System.err.println("Constructor for [" + clazz.getName() + "] does not exist"); constructor.setAccessible(true); Object instance = null; ... |
void | invokePrivateConstructor(Class invoke Private Constructor Constructor<E> constructor = classType.getDeclaredConstructor(); constructor.setAccessible(true); constructor.newInstance(); |
void | invokePrivateConstructor(Class invoke Private Constructor final Constructor<T> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
constructor.newInstance();
|
Object | invokeReflectConstruct(String className, Object[] parameter, Class[] args) invoke Reflect Construct try { Class clazz = Class.forName(className); Constructor constructor = clazz.getDeclaredConstructor(args); constructor.setAccessible(true); return constructor.newInstance(parameter); } catch (Exception e) { e.printStackTrace(); if (isThrowable) { throw new RuntimeException("invokeReflectConstruct error " + className + " parameter " + parameter); return null; |