List of utility methods to do Reflection Method Invoke
T | invokeMethod(java.lang.Object toObj, String tcMethodName, Class invoke Method try { Method loMethod = toObj.getClass().getDeclaredMethod(tcMethodName); loMethod.setAccessible(true); return (T) loMethod.invoke(toObj); } catch (NoSuchMethodException ex) { throw new RuntimeException(ex); } catch (SecurityException ex) { throw new RuntimeException(ex); ... |
Object | invokeMethod(Method inMethod, Object inObject, Object[] inArgs) invoke Method final boolean isAccessible = inMethod.isAccessible(); if (!isAccessible) { inMethod.setAccessible(true); try { return inMethod.invoke(inObject, inArgs); } finally { |
Object | invokeMethod(Method m, Object instance, Object[] args) invoke Method try { return m.invoke(instance, args); } catch (Throwable t) { throw new IllegalStateException(t); |
Object | invokeMethod(Method m, Object[] o) attempt to invoke a Method with the given Object arguments, performing static method auto-detection and automatic array compression Object obj; Object[] args; Class[] c = m.getParameterTypes(); int num = (o == null) ? 0 : o.length; int len = -1; int a = -1; if (c != null) { len = c.length; ... |
Object | invokeMethod(Method meth, String str) invoke Method try { return meth.invoke(null, str); } catch (Throwable t) { System.err.println("Error in method invocation with argument " + str + " : " + t.getMessage()); return null; |
Object | invokeMethod(Method method, Class> beanClass, Object element) invoke Method if (method != null && instanceOf(beanClass, element)) { try { return method.invoke(element, EMPTY_ARRAY); } catch (Exception e) { throw new RuntimeException(e); return null; ... |
Object | invokeMethod(Method method, Object bean, Object[] values) This just catches and wraps IllegalArgumentException. try { return method.invoke(bean, values); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " - " + e.getMessage()); |
Object | invokeMethod(Method method, Object instance, Object... parameters) A helper method to invoke a method via reflection and wrap any exceptions as RuntimeException instances if (method == null) { return null; try { return method.invoke(instance, parameters); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { ... |
Object | invokeMethod(Method method, Object object) invoke Method return method.invoke(object, EMPTY_PARAMS);
|
Object | invokeMethod(Method method, Object object, Object... args) invoke Method if (args == null || args.length == 0) { return method.invoke(object); List<Object> invokeArgs = new ArrayList<>(); for (Class<?> typeClass : method.getParameterTypes()) { for (Object arg : args) { if (arg == null) { invokeArgs.add(null); ... |