List of utility methods to do Method Call
Object | invoke(String cls_name, String method, Class>[] param_cls, Object cls, Object[] params) invoke try { Class<?> c = Class.forName(cls_name); Method m = c.getMethod(method, param_cls); return m.invoke(cls, params); } catch (Exception e) { throw new RuntimeException(e); |
void | invoke(String method) invoke try { Bundle bundle = Platform.getBundle(HELP_UI_PLUGIN_ID); if (bundle == null) { return; Class c = bundle.loadClass(LOOP_CLASS_NAME); Method m = c.getMethod(method, new Class[] {}); m.invoke(null, new Object[] {}); ... |
boolean | invoke(String methodName, Object obj) silent reflect invocation of method name if it exists Class<?> c = obj.getClass(); try { Method m = c.getMethod(methodName, NULL_CLASS_ARGS); m.invoke(obj, NULL_ARGS); } catch (Exception e) { return false; return true; ... |
Object | invoke(String methodName, Object object, Class>[] argTypes, Object[] args) invoke Method method = object.getClass().getDeclaredMethod(methodName, argTypes);
method.setAccessible(true);
return method.invoke(object, args);
|
Object | invoke(String methodName, Object target, Class targetClass, Object[] args) Invoke the given method. Class[] paramClasses = new Class[args.length]; for (int i = 0; i < args.length; i++) { paramClasses[i] = args[i].getClass(); Method method = getMethod(targetClass, methodName, paramClasses); return invoke(method, target, args); |
Object | invoke(String name, Object object, Object... args) invoke try { Class<?>[] parameterTypes = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) parameterTypes[i] = args[i].getClass(); Method method = findMethod(object.getClass(), name, parameterTypes); return method.invoke(object, args); } catch (IllegalArgumentException e) { throw new RuntimeException(e); ... |
Object | invoke_ex(Object obj, String method, Class>[] params, Object[] args) invokex Class<?> clazz = null; if (obj instanceof Class<?>) { clazz = (Class<?>) obj; } else { clazz = obj.getClass(); Method methods = clazz.getDeclaredMethod(method, params); methods.setAccessible(true); ... |
void | invokeAccessableMethodWithArguments(Object instance, String method, Object... arguments) invoke Accessable Method With Arguments Class<?>[] classes = new Class[arguments.length]; for (int x = 0; x < arguments.length; x++) { classes[x] = arguments[x].getClass(); try { instance.getClass().getMethod(method, classes).invoke(instance, arguments); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignored) { |
Collection | invokeAndCastCollection(T returnType, Method m, Object obj, Object... args) Same as ReflectionHelper#invokeAndCast(Object,Method,Object,Object) but with a cast to Collection try { return (Collection<T>) m.invoke(obj, args); } catch (Exception e) { throw new RuntimeException(e); |
void | invokeAnnotatedDeclaredMethod(Object obj, Class extends Annotation> annotationType) invoke Annotated Declared Method Optional<Method> annotatedMethod = Arrays.stream(obj.getClass().getDeclaredMethods())
.filter(method -> method.getParameterCount() == 0)
.filter(method -> method.isAnnotationPresent(annotationType)).findFirst();
if (annotatedMethod.isPresent()) {
annotatedMethod.get().invoke(obj);
|