Here you can find the source of invokeDeclaredMethod(Object object, String methodName, Object... parameters)
public static Object invokeDeclaredMethod(Object object, String methodName, Object... parameters)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.*; public class Main { public static Object invokeDeclaredMethod(Object object, String methodName, Object... parameters) { try {/* w ww .ja va 2 s .co m*/ Method method = object.getClass().getDeclaredMethod(methodName, convertToMethodParameters(parameters)); method.setAccessible(true); return method.invoke(object, parameters); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); return null; } } private static Class<?> getClass(String clazz) { try { return Class.forName(clazz); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } } private static Class<?>[] convertToMethodParameters(Object... parameters) { Class<?>[] classes = new Class<?>[parameters.length]; for (int i = 0; i < parameters.length; i++) { Class<?> clazz = parameters[i].getClass(); if (clazz == Boolean.class) { clazz = boolean.class; } else if (clazz == Byte.class) { clazz = byte.class; } else if (clazz == Character.class) { clazz = char.class; } else if (clazz == Double.class) { clazz = double.class; } else if (clazz == Float.class) { clazz = float.class; } else if (clazz == Integer.class) { clazz = int.class; } else if (clazz == Long.class) { clazz = long.class; } else if (clazz == Short.class) { clazz = short.class; } else if (clazz == Void.class) { clazz = void.class; } classes[i] = clazz; } return classes; } }