List of utility methods to do Method Call
Object | invoke(Object obj, String methodName, Object... params) invoke if (params.length % 2 != 0) { throw new RuntimeException("types and values mismatch"); try { int size = params.length / 2; Class<?>[] types = new Class<?>[size]; Object[] args = new Object[size]; for (int i = 0; i < types.length; i++) { ... |
Object | invoke(Object obj, String methodName, Object[] params) invoke try { Method[] methods = obj.getClass().getMethods(); Method method = getMethod(methods, methodName); Object result = null; if (method != null) { result = method.invoke(obj, params); } else { throw new IllegalAccessException("Not exist the method. Method Name: [" + methodName + "]"); ... |
Object | invoke(Object obj, String name, Object... args) invoke Method method = null; Class<?> clazz = obj.getClass(); for (Method met : clazz.getMethods()) { if (name.equals(met.getName())) { method = met; break; try { if (method != null) { if (args.length == 0) { return method.invoke(obj); } else { return method.invoke(obj, args); } catch (InvocationTargetException e) { return e.getCause(); } catch (Throwable e) { return e; return null; |
Object | invoke(Object object, Method method) This simpy calls Method#invoke(Object,Object) . try { return method.invoke(object); } catch (RuntimeException e) { return null; } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { return null; ... |
Object | invoke(Object object, Object[] args, String methodName) invoke Method method = object.getClass().getMethod(methodName, new Class[] {}); return method.invoke(object, args); |
Object | invoke(Object object, String function, Object... params) Dynamically invokes the specified function on an object with the given parameters. Class<? extends Object> type = object.getClass(); try { Map<Method, Integer> candidateDistances = getCompatibleMethods(type, function, params); if (candidateDistances.isEmpty()) throw new IllegalArgumentException( String.format("no suitable method found in %s for name %s and parameters %s", type, function, Arrays.toString(params))); if (candidateDistances.size() == 1) ... |
Object | invoke(Object object, String function, String parameter) Invoke function of object by String. System.out.println(function + "(" + (null == parameter ? "" : parameter) + ")"); Class<?>[] types = null; Object[] values = null; if (null == parameter) { types = new Class[] {}; values = new Object[] {}; } else { String[] parameters = parameter.split(","); ... |
T | invoke(Object object, String method, Object... args) invoke try { Class clazz = object.getClass(); Method m = clazz.getMethod(method, getClassTypes(args)); return (T) m.invoke(object, args); } catch (Exception e) { throw new RuntimeException(e); |
Object | invoke(Object object, String methodName) invoke Class<?> objectClass = object.getClass(); Method method; try { method = objectClass.getMethod(methodName, new Class<?>[] {}); } catch (NoSuchMethodException e) { method = objectClass.getDeclaredMethod(methodName, new Class<?>[] {}); method.setAccessible(true); return method.invoke(object, new Object[] {}); |
Object | invoke(Object object, String methodName, Class>[] argTypes, Object... args) invoke try { Method onLayout = object.getClass().getDeclaredMethod(methodName, argTypes); onLayout.setAccessible(true); return onLayout.invoke(object, args); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); ... |