List of utility methods to do Reflection Method Invoke
Object | invokeMethod(Object object, String methodName, Object arg, Class argType) invoke Method return invokeMethod(object, methodName, new Object[] { arg }, new Class[] { argType }); |
T | invokeMethod(Object object, String methodName, Object... parameters) Invokes the method with the given name of the specified object, with the specified parameters. try { Class[] parameterTypes = new Class[parameters.length]; for (int i = 0; i < parameters.length; i++) { Object arg = parameters[i]; parameterTypes[i] = arg.getClass(); Method method; if (object instanceof Class) { ... |
Object | invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes) Invoke a named method whose parameter type matches the object type. if (parameterTypes == null) { parameterTypes = emptyClassArray; if (args == null) { args = emptyObjectArray; Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes); if (method == null) ... |
boolean | invokeMethod(Object object, String methodName, Object[] params, Object[] result) Find and invoke the method on the object if it exists. if (object == null) return false; boolean retval = false; Method method = null; Class<?>[] paramTypes = params == null ? null : new Class<?>[params.length]; if (params != null) { for (int i = 0; i < params.length; ++i) { paramTypes[i] = params[i] == null ? null : params[i].getClass(); ... |
Object | invokeMethod(Object object, String name, Object... arguments) invoke Method Class<?> clazz = object.getClass(); Class<?> argumentClasses[] = new Class<?>[arguments.length]; for (int argumentId = 0; argumentId < arguments.length; argumentId++) { argumentClasses[argumentId] = arguments[argumentId].getClass(); Method field = clazz.getDeclaredMethod(name, argumentClasses); boolean accessable = field.isAccessible(); if (!accessable) ... |
Object | invokeMethod(Object object, String propertyName) invoke Method try { Method getterMethod = object.getClass().getMethod(propertyName); return getterMethod.invoke(object); } catch (Exception e) { e.printStackTrace(); return null; |
Object | invokeMethod(Object objectInstance, String methodToInvoke, Class[] parameterTypes, Object[] instanceParameters) invoke Method Method method = objectInstance.getClass().getMethod(methodToInvoke, parameterTypes);
Object retVal = method.invoke(objectInstance, instanceParameters);
return retVal;
|
Object | invokeMethod(Object owner, String methodName) invoke Method return invokeMethod(owner, methodName, new Object[] {}); |
Object | invokeMethod(Object owner, String methodName, Object[] args) Invoke method. Class<?> ownerClass = owner.getClass(); Class<?>[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); Method method = ownerClass.getMethod(methodName, argsClass); return method.invoke(owner, args); |
void | invokeMethod(Object parent, String method, Class>[] paramTypes, Object[] args) invoke Method try { parent.getClass().getMethod(method, paramTypes).invoke(parent, args); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); ... |