Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Object genericInvokeMethod(Object obj, String methodName, Object...params) {
- int paramCount = params.length;
- Method method;
- Object requiredObj = null;
- Class << ? > [] classArray = new Class << ? > [paramCount];
- for (int i = 0; i < paramCount; i++) {
- classArray[i] = params[i].getClass();
- }
- try {
- method = obj.getClass().getDeclaredMethod(methodName, classArray);
- method.setAccessible(true);
- requiredObj = method.invoke(obj, params);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- return requiredObj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement