Here you can find the source of invoke(Object instance, String method, Class[] paramTypes, Object... parameters)
public static Object invoke(Object instance, String method, Class[] paramTypes, Object... parameters)
//package com.java2s; //License from project: Apache License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; public class Main { public static Object invoke(Object instance, String method, Object... parameters) throws Throwable { Class clazz = instance.getClass(); for (Method m : clazz.getMethods()) { if (m.getName().equals(method)) { try { return m.invoke(instance, parameters); } catch (IllegalArgumentException e) { throw new RuntimeException("Can't invoke method", e); } catch (IllegalAccessException e) { throw new RuntimeException("Can't invoke method", e); } catch (InvocationTargetException e) { throw e.getTargetException(); }/* w w w. j av a 2 s .co m*/ } } throw new RuntimeException("Can't find method"); } public static Object invoke(Object instance, String method, Class[] paramTypes, Object... parameters) { Class clazz = instance.getClass(); for (Method m : clazz.getMethods()) { if (m.getName().equals(method) && Arrays.equals(m.getParameterTypes(), paramTypes)) { try { return m.invoke(instance, parameters); } catch (Exception e) { throw new RuntimeException("Can't invoke method", e); } } } throw new RuntimeException("Can't find method"); } }