ClassUtils { public static <T extends Annotation> T getAnnotationOnMethod(Class<?> clazz, String fieldName, Class<T> annotationClass) { Method method = getGetterMethod(clazz, fieldName); if (method != null) { return getAnnotationOnMethod(method, annotationClass); } return null; } 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 testGetAnnotationOnMethod() { Attribute attribute = ClassUtils.getAnnotationOnMethod(TestObject.class, "fieldThree", Attribute.class); assertNotNull(attribute); assertEquals("Bert", attribute.displayName()); }