List of utility methods to do Reflection Method Invoke
T | invokeMethod(Class invoke Method Class[] classes = new Class[objects.length]; for (int i = 0; i < objects.length; i++) { classes[i] = objects[i].getClass(); Method method = ivokeObject.getClass().getDeclaredMethod(methodName, classes); method.setAccessible(true); return (T) method.invoke(ivokeObject, objects); |
T | invokeMethod(final Method method, final Object instance, final Object... args) invoke Method final boolean acc = method.isAccessible(); method.setAccessible(true); try { return (T) method.invoke(instance, args); } catch (Exception e) { throw new IllegalStateException(String.format("Failed to invoke method '%s#%s(%s)'", method.getDeclaringClass(), method.getName(), Arrays.toString(args)), e); } finally { ... |
Object | invokeMethod(final Method method, final Object object) Invoke the givenMethod on a givenObject. return invokeMethod(method, object, (Object[]) null);
|
Object | invokeMethod(final Method method, final Object object, final Object[] args) invoke Method try { return method.invoke(object, args); } catch (final InvocationTargetException e) { throw e.getTargetException(); |
Object | invokeMethod(final Object instance, final String methodName, final Class>[] parTypes, final Object[] parameters) invoke Method assert instance != null && methodName != null && parTypes != null && parameters != null; final Method method = getMethod(instance.getClass(), methodName, parTypes, parameters); method.setAccessible(true); return method.invoke(instance, parameters); |
T | invokeMethod(final Object obj, final Method method, final Object... args) Invoke the method with the given argument on the given object. T result = null; method.setAccessible(true); try { result = (T) method.invoke(obj, args); } catch (final Exception e) { throw new RuntimeException("Can't invoke method " + method + " from " + obj, e); } finally { method.setAccessible(false); ... |
Object | invokeMethod(final Object obj, final String methodName, final boolean throwException) Invoke the named method in the given object or its superclasses. if (obj != null) { final Class<? extends Object> cls = obj.getClass(); final List<Class<?>> reverseAttemptOrder = getReverseMethodAttemptOrder(cls); IllegalAccessException illegalAccessException = null; for (int i = reverseAttemptOrder.size() - 1; i >= 0; i--) { final Class<?> iface = reverseAttemptOrder.get(i); try { final Method method = iface.getDeclaredMethod(methodName); ... |
Object | invokeMethod(final Object object, final String methodName, final Class>[] parameterTypes, final Object[] parameters) invoke Method Method method = getDeclaredMethod(object, methodName, parameterTypes); if (method == null) throw new IllegalArgumentException( "Could not find method [" + methodName + "] on target [" + object + "]"); method.setAccessible(true); try { return method.invoke(object, parameters); } catch (IllegalAccessException e) { ... |
Object | invokeMethod(final Object object, final String methodName, final Class>[] paramTypes, final Object[] parameters) invoke Method final Method method = getDeclaredMethod(object, methodName, paramTypes); method.setAccessible(true); return method.invoke(object, parameters); |
Object | invokeMethod(final Object p, final String methodName) invoke Method Method meth = p.getClass().getMethod(methodName);
return meth.invoke(p);
|