List of utility methods to do Method Call
Iterator> | invokeIteratorCallable(String callableClassName, ClassLoader cl) invoke Iterator Callable Class<?> klass = Class.forName(callableClassName, true, cl); Constructor<?> ctor = klass.getDeclaredConstructor(); Object instance = ctor.newInstance(); Method callMethod = klass.getMethod("call"); return (Iterator<?>) callMethod.invoke(instance); |
Object | invokeMXMethod(String methodName) invoke MX Method OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
Method m = operatingSystemMXBean.getClass().getDeclaredMethod(methodName);
m.setAccessible(true);
return m.invoke(operatingSystemMXBean);
|
T | invokeNoArgs(Object instance, Method method, Class Invokes the method, using the provided instance as 'this', and casts the return value to the provided return type. try { if (!method.isAccessible()) { method.setAccessible(true); final Object returnValue = method.invoke(instance, NO_ARGS); return returnType.cast(returnValue); } catch (Exception e) { final String message = String.format("Error invoking no-args method: class=%s, method=%s", ... |
Object | invokeNoArgsMethod(Object object, String methodName) Invoke no args method from the given instance. Method declaredMethod = null; try { declaredMethod = object.getClass().getDeclaredMethod(methodName, (Class<?>[]) null); declaredMethod.setAccessible(true); return declaredMethod.invoke(object, (Object[]) null); } catch (Exception e) { throw new IllegalStateException("Failed to invoke method: " + methodName, e); |
Object | invokeNonAccessibleMethod(Class> clazz, String methodName, Object instance, Object... params) invoke Non Accessible Method List<Class<?>> targetParamTypes = new ArrayList<Class<?>>(); if (params != null) { for (Object param : params) { targetParamTypes.add(param.getClass()); Object retVal = null; try { ... |
Object | invokeNonArgMethod(Object object, String methodName) invoke Non Arg Method Class<?> clazz = object.getClass(); try { return clazz.getMethod(methodName).invoke(object); } catch (NoSuchMethodException ex) { throw new IllegalArgumentException(String.format("Class should declare method %s()", methodName)); } catch (InvocationTargetException | IllegalAccessException ex) { throw new IllegalStateException(ex); |
Object | invokeObjectMethod(Object object, String name, Class> paramTypes[], Object args[]) invoke Object Method Method method = object.getClass().getMethod(name, paramTypes); if (!method.isAccessible()) { method.setAccessible(true); try { return method.invoke(object, args); } catch (InvocationTargetException e) { throw e.getTargetException(); ... |
Object | invokeOrBailOut(Object invokee, Method method, Object[] params) Utility method that invokes a method and does the error handling around the invocation. try { return method.invoke(invokee, params); } catch (IllegalArgumentException e) { throw new Error(createMessage(invokee, method, params), e); } catch (IllegalAccessException e) { throw new Error(createMessage(invokee, method, params), e); } catch (InvocationTargetException e) { throw new Error(createMessage(invokee, method, params), e); ... |
Object | invokeParameterlessMethod(T theObject, String methodName) invoke Parameterless Method Method method = theObject.getClass().getDeclaredMethod(methodName, null);
method.setAccessible(true);
return method.invoke(theObject, null);
|
void | invokePrepare(Object instance) Try to invoke the prepare() method on the provided object instance. if (instance == null) { return; try { instance.getClass().getMethod("prepare").invoke(instance); } catch (NoSuchMethodException | SecurityException ex) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { |