Here you can find the source of invokeReflectStaticMethod(String methodName, Class cl, Object[] parameter, Class[] args)
public static Object invokeReflectStaticMethod(String methodName, Class cl, Object[] parameter, Class[] args)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static boolean isThrowable = true; public static Object invokeReflectStaticMethod(String methodName, Class cl, Object[] parameter, Class[] args) { try {//from w ww . j ava 2 s. c o m Method method = cl.getDeclaredMethod(methodName, args); method.setAccessible(true); return method.invoke(null, parameter); } catch (Exception e) { e.printStackTrace(); } if (isThrowable) { throw new RuntimeException("invokeReflectStaticMethod error " + methodName + " class " + cl + " args " + args); } return null; } public static Method getDeclaredMethod(Object object, String methodName, Class[] parameterTypes, Class declaringClass) { Method method = null; if (null == declaringClass || !declaringClass.isInterface()) { for (Class<?> clazz = object.getClass(); clazz != null; clazz = clazz .getSuperclass()) { try { method = clazz.getDeclaredMethod(methodName, parameterTypes); if (!method.isAccessible()) { method.setAccessible(true); } if (null == declaringClass || clazz.equals(declaringClass)) { return method; } } catch (Exception e) { } } } else { try { method = declaringClass.getDeclaredMethod(methodName, parameterTypes); return method; } catch (Exception e) { } } if (isThrowable) { throw new RuntimeException("getDeclaredMethod error " + methodName + " parameterTypes " + parameterTypes + " targetObject " + object.toString()); } return null; } }