Here you can find the source of invoke(Class> clazz, Object obj, String methodName, Object... args)
public static Object invoke(Class<?> clazz, Object obj, String methodName, Object... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Object invoke(Class<?> clazz, Object obj, String methodName, Object... args) { try {//from w w w. j ava 2s. c o m Method method = findMethod(clazz, methodName); method.setAccessible(true); Object result = method.invoke(obj, args); return result; } catch (Throwable e) { throw new RuntimeException("invoke", e); } } public static Method findMethod(Class<?> clazz, String methodName) { for (Method method : clazz.getDeclaredMethods()) if (method.getName().equalsIgnoreCase(methodName)) return method; return null; } public static Method findMethod(Class<?> clazz, String method, Class<?>... prmTypes) { try { return clazz.getMethod(method, prmTypes); } catch (Exception e) { return null; } } }