Here you can find the source of invokeStaticMethod(Class objClass, String methodName, Object args[])
Parameter | Description |
---|---|
objClass | a parameter |
methodName | a parameter |
args | a parameter |
public static Object invokeStaticMethod(Class objClass, String methodName, Object args[])
//package com.java2s; import java.lang.reflect.Method; public class Main { /**/* w w w . j a v a 2 s. c o m*/ * invoke Static Method * * @param objClass * @param methodName * @param args * @return */ public static Object invokeStaticMethod(Class objClass, String methodName, Object args[]) { Object result = null; try { Class argClasses[] = null; if (args != null && args.length > 0) { argClasses = new Class[args.length]; for (int i = 0, max = args.length; i < max; i++) { argClasses[i] = (args[i] == null) ? null : args[i].getClass(); } } Method method = getMethod(objClass, methodName, argClasses); result = method.invoke(null, args); } catch (Exception e) { // logger.debug(e); } return result; } /** * get Method * * @param objClass * @param methodName * @param argClass * @return Method * @throws Exception */ public static Method getMethod(Class objClass, String methodName, Class argClass) throws Exception { Class argClasses[] = (argClass == null) ? null : new Class[] { argClass }; return getMethod(objClass, methodName, argClasses); } /** * get Method * * @param objClass * @param methodName * @param argClasses * @return * @throws Exception */ public static Method getMethod(Class objClass, String methodName, Class argClasses[]) throws Exception { Method method = null; try { method = objClass.getDeclaredMethod(methodName, argClasses); } catch (Exception e) { } if (method == null) { try { method = objClass.getMethod(methodName, argClasses); } catch (Exception e) { // logger.debug(e); } } return method; } }