List of utility methods to do Method Call
T | invoke(Object object, String methodName, Class Invoke a method. Class<?>[] parameterTypes = new Class<?>[parameters.length]; for (int i = 0; i < parameters.length; i++) { parameterTypes[i] = parameters[i] == null ? Object.class : parameters[i].getClass(); Method method = object.getClass().getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return returnType.cast(method.invoke(object, parameters)); |
Object | invoke(Object object, String methodName, Object[] args) invoke if (object == null) { throw new NullPointerException(); Method method = getMatchingMethod(object.getClass(), methodName, args); return method.invoke(object, args); |
Object | invoke(Object objToInvoke, Class> classToInvoke, String method, Class[] argumentClasses, Object[] arguments) Invoke a method via reflection Method m = classToInvoke.getDeclaredMethod(method, argumentClasses); Object o; if (m.isAccessible()) o = m.invoke(objToInvoke, arguments); else { m.setAccessible(true); o = m.invoke(objToInvoke, arguments); m.setAccessible(false); ... |
T | invoke(Object owner, String methodName) invoke Method m; try { m = owner.getClass().getDeclaredMethod(methodName); } catch (NoSuchMethodException e) { throw new RuntimeException(e); m.setAccessible(true); try { ... |
java.lang.Object | invoke(Object proxy, java.lang.reflect.Method method, Object[] args) invoke return method.invoke(proxy, args);
|
Object | invoke(Object source, String key) invoke if (source instanceof Map) { return valueOfMap((Map) source, key); } else { return valueOfObj(source, key); |
Object | invoke(Object target, Class> clazz, String methodName, Class[] parameterTypes, Object... args) Convenience wrapper to reflection method invoke API. try { Method method = null; try { method = clazz.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { method = clazz.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); ... |
T | invoke(Object target, Class invoke try { Method m = target.getClass().getMethod(method); return clazz.cast(m.invoke(target)); } catch (Throwable t) { throw new RuntimeException(t); |
Object | invoke(Object target, Method method) invoke requireNonNull(target, "target is null"); requireNonNull(method, "method is null"); try { return method.invoke(target); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw new MBeanException((RuntimeException) targetException, ... |
Object | invoke(Object target, String methodName) invoke return invoke(target, methodName, NO_ARGS);
|