Here you can find the source of invoke(E e, String methodName)
public static <E> Object invoke(E e, String methodName)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static <E> Object invoke(E e, String methodName) { return invoke(e, methodName, new Object[0]); }/* w w w .j a va 2 s. c om*/ @SuppressWarnings("unchecked") public static <E> Object invoke(E e, String methodName, Object... params) { Class<E> clazz = (Class<E>) e.getClass(); try { Method method = clazz.getDeclaredMethod(methodName, paramsClasses(params)); method.setAccessible(true); return method.invoke(e, params); } catch (Exception ex) { throw new RuntimeException("Cannot execute " + methodName, ex); } } private static Class<?>[] paramsClasses(Object... params) { if (params == null || params.length == 0) { return new Class<?>[0]; } Class<?>[] classez = new Class<?>[params.length]; for (int i = 0; i < params.length; i++) { Object obj = params[i]; if (obj == null) { classez[i] = null; } else { classez[i] = obj.getClass(); } } return classez; } }