ClassUtils { public static boolean hasMethod(Object obj, String methodName) { Method[] methods = obj.getClass().getMethods(); for (Method method : methods) { if (method.getName().equals(methodName) && (Modifier.isPublic(method.getModifiers()))) { return true; } } return false; } private  ClassUtils(); static boolean canSetProperty(Object obj, String fieldName); static void clearFieldValue(Object obj, String fieldName, Class<?> argType); static Class<?> forClass(final String clazz); static T getAnnotation(Class<?> clazz, String fieldName, Class<T> annotationClass); @SuppressWarnings("unchecked") static R getAnnotationAttributeValue(Field field, Class<T> annotationClass, String attributeName); static T getAnnotationOnField(Class<?> clazz, String fieldName, Class<T> annotationClass); @SuppressWarnings("unchecked") static T getAnnotationOnField(Field field, Class<T> annotationClass); static T getAnnotationOnMethod(Class<?> clazz, String fieldName, Class<T> annotationClass); @SuppressWarnings("unchecked") static T getAnnotationOnMethod(Method method, Class<T> annotationClass); static byte[] getBytes(Object obj, String fieldName); static Constructor<T> getConstructor(Class<T> clazz, Object... args); static Field getField(Class<?> clazz, String fieldName); static Object getFieldValue(Object obj, String fieldName); static String getFieldValueAsString(Object obj, String fieldName); static String getFieldValueAsString(Object obj, String fieldName, String defValue); static Method getGetterMethod(Class<?> clazz, String fieldName); static int getMaxLength(Class<?> clazz, String fieldName); static PropertyDescriptor getPropertyDescriptorForNestedProperty(Class<?> clazz, String property); static Class<?> getResolvedType(Class<T> type, String fieldName, int... indexes); static Class<?> getResolvedType(Object object, int... indexes); static boolean hasMethod(Object obj, String methodName); static T instantiateClass(Class<T> clazz, Object... args); static void setBytes(byte[] bytes, Object obj, String fieldName); static void setFieldValue(Object obj, String fieldName, Object value); static void copyFields(T from, S to);  }
@Test public void testHasMethod() { TestEntity entity = new TestEntity(); assertTrue(ClassUtils.hasMethod(entity, "getAge")); assertTrue(ClassUtils.hasMethod(entity, "getSomeBoolean")); assertFalse(ClassUtils.hasMethod(entity, "getAGe")); assertFalse(ClassUtils.hasMethod(entity, "age")); }