Here you can find the source of invokeMethod(Object owner, String methodName, Object[] args)
Parameter | Description |
---|---|
owner | the owner |
methodName | the method name |
args | the args |
Parameter | Description |
---|---|
Exception | the exception |
public static Object invokeMethod(Object owner, String methodName, Object[] args) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { /**//from w ww . jav a2 s . c o m * Invoke method. * * @param owner * the owner * @param methodName * the method name * @param args * the args * @return the object * @throws Exception * the exception */ public static Object invokeMethod(Object owner, String methodName, Object[] args) throws Exception { Class<?> ownerClass = owner.getClass(); Class<?>[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); } Method method = ownerClass.getMethod(methodName, argsClass); return method.invoke(owner, args); } }