Is Field Annotation Present : Annotation « Reflection « Java





Is Field Annotation Present

    

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class Util{
  public static boolean isFieldAnnotationPresent(Class<?> clazz, String fieldName, Class<? extends Annotation> annotationClass) throws NoSuchFieldException {
    Field field = clazz.getDeclaredField(fieldName);
    return(field.isAnnotationPresent(annotationClass));
  }
}

   
    
    
    
  










Related examples in the same category

1.Uses reflection to display the annotation associated with a method.
2.Get annotation by annotation class
3.Show all annotations for a class and a method.
4.default values in an annotation.
5.Does a method have an annotation
6.Get Annotation Parameter
7.A better concise toString method for annotation types
8.Find Annotated Method
9.Find Annotated Fields
10.Get default annotation value
11.Get annotation value
12.Get Annotated Declared Fields