Here you can find the source of invokeMethod(Class extends E> clazz, E instance, String[] names, Object... args)
public static <T, E> Object invokeMethod(Class<? extends E> clazz, E instance, String[] names, Object... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static <T, E> Object invokeMethod(Class<? extends E> clazz, E instance, String[] names, Object... args) { try {/*ww w . j a v a 2s.com*/ Method method = getMethod(clazz, names); if (method != null) return method.invoke(instance, args); } catch (Exception ex) { ex.printStackTrace(); } return null; } public static Method getMethod(Class<?> clazz, String... names) { try { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { for (String methodName : names) { if (method.getName().equalsIgnoreCase(methodName)) { method.setAccessible(true); return method; } } } } catch (Exception e) { throw e; } return null; } }