ReflectUtils { public static Method getMethod(String clazzName, String methodName, String[] argsType) { Class clazz = ClassUtils.forName(clazzName); Class[] classes = ClassTypeUtils.getClasses(argsType); return getMethod(clazz, methodName, classes); }  static boolean isPrimitives(Class<?> clazz); static String getCodeBase(Class<?> cls); static Method getMethod(String clazzName, String methodName, String[] argsType); static Method getMethod(Class clazz, String methodName, Class... argsType); static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz); static Method getPropertyGetterMethod(Class clazz, String property);  }
@Test public void testGetMethod() throws Exception { String className = "com.alipay.sofa.rpc.common.utils.TestBean"; String methodName = "setAlias"; String[] argsType1 = new String[] { "java.lang.String" }; Method method = ReflectUtils.getMethod(className, methodName, argsType1); Method method3 = ClassUtils.forName(className).getMethod(methodName, ClassTypeUtils.getClasses(argsType1)); Assert.assertFalse(method == method3); Assert.assertTrue(method.equals(method3)); Method method4 = ReflectUtils.getMethod(TestBean.class, "setAlias", String.class); Assert.assertFalse(method == method4); Assert.assertTrue(method3.equals(method4)); boolean error = false; try { ReflectUtils.getMethod(className, methodName + "xxx", argsType1); } catch (Exception e) { error = true; } Assert.assertTrue(error); }