List of utility methods to do Method Call
Object | invokeAnUnwrapException(final Method method, final Object[] args, final Object target) invoke An Unwrap Exception try { return method.invoke(target, args); } catch (InvocationTargetException ite) { throw ite.getTargetException(); |
void | invokeCallback(String callbackName, String callbackParam) invoke Callback int a = callbackName.lastIndexOf('/'); if (a < 0) { throw new IllegalStateException("bad callback format (should be ab/cd/className/methName)"); String className = METHOD_SEPARATOR.matcher(callbackName.substring(0, a)).replaceAll("."); String methodName = callbackName.substring(a + 1); try { Class<?> clazz = Class.forName(className); ... |
void | invokeCmd(String className, String[] args) invoke Cmd Class<?> cmd = null; try { cmd = Class.forName(className); } catch (ClassNotFoundException ex) { System.err.println("Class '" + className + "' not found"); System.exit(1); Method method = null; ... |
Object | invokeDeclared(Class c, Object obj, String method, Class[] paramClasses, Object[] params) Invokes any method of a class, even private ones. Method m = c.getDeclaredMethod(method, paramClasses);
m.setAccessible(true);
return m.invoke(obj, params);
|
Object | invokeDeclared(Class c, Object obj, String method, Class[] paramClasses, Object[] params) invoke Declared Method m = c.getDeclaredMethod(method, paramClasses);
m.setAccessible(true);
return m.invoke(obj, params);
|
Object | invokeDeclaredMethod(Object object, String methodName, Object... parameters) invoke Declared Method try { Method method = object.getClass().getDeclaredMethod(methodName, convertToMethodParameters(parameters)); method.setAccessible(true); return method.invoke(object, parameters); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); return null; |
Object | invokeDeclaredMethod(String methodName, Object target, Class[] parameterTypes, Object[] parameters) invoke Declared Method Method method = target.getClass().getDeclaredMethod(methodName, parameterTypes);
return invokeMethod(method, target, parameters);
|
void | invokeDeclaredMethodWithAnnotation(Class extends Annotation> annotationClass, Object target) invoke Declared Method With Annotation Method[] declaredMethods = target.getClass().getDeclaredMethods(); for (Method declaredMethod : declaredMethods) { Annotation annotation = declaredMethod.getAnnotation(annotationClass); if (annotation != null) { invokeMethod(declaredMethod, target, new Object[] {}); |
Object | invokeDefaultMethod(final Method method, final Object[] args, final Object proxy) invoke Default Method try { Class<?> MHclass = Class.forName("java.lang.invoke.MethodHandles"); Object lookup = MHclass.getMethod("lookup", (Class<?>[]) null).invoke(null, (Object[]) null); Constructor<?> constructor = lookup.getClass().getDeclaredConstructor(Class.class); constructor.setAccessible(true); Object newLookupInstance = constructor.newInstance(method.getDeclaringClass()); Object in = newLookupInstance.getClass().getMethod("in", new Class<?>[] { Class.class }) .invoke(newLookupInstance, method.getDeclaringClass()); ... |
boolean | invokedMethod(java.lang.Object closure, java.lang.Class> targetClass, java.lang.String targetMethod) Test whether the given closure invokes the specified method in the specified class. throw new RuntimeException(); |