Java tutorial
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Object paramObject, String paramString) { return invokeMethod((Object) paramObject, (String) paramString, (Object[]) null); } public static Object invokeMethod(Object paramObject, String paramString, Class<?>[] paramArrayOfClass, Object[] paramArrayOfObject) { Class localClass = paramObject.getClass(); try { Method localException = localClass.getDeclaredMethod(paramString, paramArrayOfClass); localException.setAccessible(true); return localException.invoke(paramObject, paramArrayOfObject); } catch (Exception var9) { Method localMethod = null; try { if (localClass != null && localClass.getSuperclass() != null) { localMethod = localClass.getSuperclass().getDeclaredMethod(paramString, paramArrayOfClass); if (localMethod != null) { localMethod.setAccessible(true); return localMethod.invoke(paramObject, paramArrayOfObject); } } } catch (Exception var8) { ; } return null; } } public static Object invokeMethod(Object paramObject, String paramString, Object[] paramArrayOfObject) { return invokeMethod(paramObject, paramString, getArgsClasses(paramArrayOfObject), paramArrayOfObject); } public static Object invokeMethod(Method method, Object receiver, Object... args) { try { return method.invoke(receiver, args); } catch (IllegalArgumentException var4) { ; } catch (IllegalAccessException var5) { ; } catch (InvocationTargetException var6) { ; } return null; } public static Object invokeMethod(Class<?> methodClass, String methodName, Class<?>[] parameters, Object instance, Object... arguments) { try { Method e = methodClass.getDeclaredMethod(methodName, parameters); e.setAccessible(true); return e.invoke(instance, arguments); } catch (Exception var6) { var6.printStackTrace(); return null; } } private static Class<?>[] getArgsClasses(Object[] paramArrayOfObject) { Class[] arrayOfClass = null; if (paramArrayOfObject != null) { arrayOfClass = new Class[paramArrayOfObject.length]; for (int i = 0; i < paramArrayOfObject.length; ++i) { if (paramArrayOfObject[i] != null) { arrayOfClass[i] = paramArrayOfObject[i].getClass(); if (arrayOfClass[i] == Integer.class) { arrayOfClass[i] = Integer.TYPE; } else if (arrayOfClass[i] != String.class) { if (arrayOfClass[i] == Boolean.class) { arrayOfClass[i] = Boolean.TYPE; } else if (arrayOfClass[i] == Long.class) { arrayOfClass[i] = Long.TYPE; } } } } } return arrayOfClass; } }