@Test void annotationNotPresent() { Field field = ClassUtil.getDeclaredField(ClassWithStringField.class, "stringField"); Optional<XmlAttribute> result = FieldUtil.annotation(XmlAttribute.class, field); assertThat(result, is(Optional.empty())); }
public static <A extends Annotation> Optional<A> annotation(Class<A> annotationClass, Field field) { return Optional.ofNullable(field.getAnnotation(annotationClass)); }
FieldUtil extends UtilityClass { public static <A extends Annotation> Optional<A> annotation(Class<A> annotationClass, Field field) { return Optional.ofNullable(field.getAnnotation(annotationClass)); } }
FieldUtil extends UtilityClass { public static <A extends Annotation> Optional<A> annotation(Class<A> annotationClass, Field field) { return Optional.ofNullable(field.getAnnotation(annotationClass)); }  }
FieldUtil extends UtilityClass { public static <A extends Annotation> Optional<A> annotation(Class<A> annotationClass, Field field) { return Optional.ofNullable(field.getAnnotation(annotationClass)); }  static void set(Field field, Object target, Object value); static Object get(Field field, Object target); static Object get(String fieldName, Object target); static Optional<Class<?>> genericTypeArgument(Field field, int index); static boolean hasAnnotation(Class<? extends Annotation> annotationClass, Field field); static Optional<A> annotation(Class<A> annotationClass, Field field); }
FieldUtil extends UtilityClass { public static <A extends Annotation> Optional<A> annotation(Class<A> annotationClass, Field field) { return Optional.ofNullable(field.getAnnotation(annotationClass)); }  static void set(Field field, Object target, Object value); static Object get(Field field, Object target); static Object get(String fieldName, Object target); static Optional<Class<?>> genericTypeArgument(Field field, int index); static boolean hasAnnotation(Class<? extends Annotation> annotationClass, Field field); static Optional<A> annotation(Class<A> annotationClass, Field field);  }