List of utility methods to do Reflection Method Invoke
Object | invokeMethod(Method method, Object target, Object[] args) Invoke the specified Method against the supplied target object with the supplied arguments. try { return method.invoke(target, args); } catch (Exception ex) { handleReflectionException(ex); throw new IllegalStateException("Should never get here"); |
Object | invokeMethod(Method method, Object theObject, Object[] args) Invokes a method on the specified object with the specified parameters. try { return method.invoke(theObject, args); } catch (InvocationTargetException e) { throw e.getTargetException(); |
Object | invokeMethod(Method method, Object... arguments) invoke Method return invokeMethod(null, method, arguments);
|
T | invokeMethod(Object bean, Method method, Object... param) invoke Method try { method.setAccessible(true); return (T) method.invoke(bean, param); } catch (Exception e) { if (e instanceof InvocationTargetException) { Exception cause = (Exception) e.getCause(); if (cause != null) e = cause; ... |
Object | invokeMethod(Object bean, Method method, Object[] args) Invokes supplied method against the supplied bean return method.invoke(bean, args);
|
Object | invokeMethod(Object caller, Object classInstance, String className, String methodName, String parameterClasses[], Object[] parameters) Invokes/call a method. Object result = null; try { Class<?> clazz = caller.getClass().getClassLoader().loadClass(className); Class<?> paramClasses[] = new Class<?>[0]; if (parameterClasses != null && parameterClasses.length > 0) { paramClasses = new Class<?>[parameterClasses.length]; for (int i = 0; i < parameterClasses.length; i++) paramClasses[i] = caller.getClass().getClassLoader().loadClass(parameterClasses[i]); ... |
Object | invokeMethod(Object caller, String methodName, Object[] params) invoke method and returns it result(s) Method method = null;
Class<?>[] paramTypes = (params == null ? null : getObjectTypes(params));
method = findMethod(caller.getClass(), methodName, paramTypes);
return (method == null ? null : method.invoke(caller, params));
|
E | invokeMethod(Object classInstance, Method method, Object... args) invoke Method if (method == null) { return null; try { return (E) method.invoke(classInstance, args); } catch (InvocationTargetException e) { if (e.getCause() instanceof Error) { throw (Error) e.getCause(); ... |
void | invokeMethod(Object cls, String methodName, Class> paramClass, String paramValue) invoke Method try { Method method = cls.getClass().getMethod(methodName, new Class[] { paramClass }); method.invoke(cls, new Object[] { paramValue }); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; throw e; |
void | invokeMethod(Object destination, String methodName, Object argument) Invokes the given method with the given argument. Class argumentClass = argument.getClass(); Class[] argsClasses = { argumentClass }; if (argument instanceof Boolean) { try { destination.getClass().getMethod(methodName, argsClasses); } catch (NoSuchMethodException nsmex) { argumentClass = Boolean.TYPE; } else if (argument instanceof Number) { try { destination.getClass().getMethod(methodName, argsClasses); } catch (NoSuchMethodException nsmex) { argumentClass = (Class) argumentClass.getDeclaredField("TYPE").get(argument); Class[] argsClasses2 = { argumentClass }; Object[] args = { argument }; Method setMethod = destination.getClass().getMethod(methodName, argsClasses2); setMethod.invoke(destination, args); |