List of utility methods to do Method Call
Object | invokeExactField(Object object, String fieldName) Retrieve a field whose value is returned as an object. Field field = object.getClass().getDeclaredField(fieldName); if (field == null) throw new NoSuchFieldException( "No such accessible field: " + fieldName + " on object: " + object.getClass().getName()); return field.get(object); |
Object | invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes) Invoke a method whose parameter types match exactly the parameter types given. if (args == null) { args = emptyObjectArray; if (parameterTypes == null) { parameterTypes = emptyClassArray; Method method = getAccessibleMethod(object.getClass(), methodName, parameterTypes); if (method == null) ... |
Object | invokeFunction(Object iFunction, String funcName, String param) invoke Function Method m = null; try { m = iFunction.getClass().getMethod(funcName, new Class[] { String.class }); } catch (SecurityException e) { e.printStackTrace(); return null; } catch (NoSuchMethodException e) { e.printStackTrace(); ... |
Object | invokeFunctions(Object iFunction, String funcName) invoke Functions Method m = null; try { m = iFunction.getClass().getMethod(funcName, new Class[] {}); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); Object retObj = null; try { retObj = m.invoke(iFunction, new Object[] {}); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); return retObj; |
Object | invokeGenericMethodOneArg(final Object obj, final String methodName, final Object arg) Dirty method to call a declared method with a generic parameter type. final Class<?> objClass = obj.getClass(); final Class<?> argClass = arg.getClass(); Method methodFound = null; boolean denyObject = false; for (final Method method : objClass.getDeclaredMethods()) { if (method.getName().equals(methodName)) { final Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1) { ... |
Object | invokeGet(Object o, String fieldName) invoke Get Method method = getGetMethod(o.getClass(), fieldName); try { return method.invoke(o, new Object[0]); } catch (Exception e) { e.printStackTrace(); return null; |
String | invokeGetClasspathMethodIfItExists(ClassLoader cl) invoke Get Classpath Method If It Exists Class<?> clazz = cl.getClass(); try { Method m = clazz.getMethod("getClasspath"); Object returnValue = m.invoke(cl); if (returnValue instanceof String) { return (String) returnValue; } else { return null; ... |
Object | invokeGetMethodWithSameName(Object object, Method method) invoke Get Method With Same Name String methodName = "get" + method.getName().substring(3); Method getMethod = object.getClass().getMethod(methodName, new Class[0]); return getMethod.invoke(object, new Object[0]); |
Method | invokeHeritedMethod(Object target, String method, Class> klass) invoke Herited Method if (klass == null) { throw new NoSuchMethodException(); Method m; try { m = klass.getDeclaredMethod(method); } catch (NoSuchMethodException e) { return invokeHeritedMethod(target, method, klass.getSuperclass()); ... |
Object | invokeInstanceMethod(Object target, String methodName, Class> type, Object arg) Invoke method. return invokeInstanceMethod(target, methodName, new Class[] { type }, new Object[] { arg }); |