4 Replies Latest reply on Sep 16, 2008 9:15 PM by brucechapman

    Parsing annotations configured on a field


      I have a class
      public abstract class RulesPropertiesSpecification extends AbstractMLFact implements Cloneable {
           private int minAge;
           private int maxAge;
           private Collection<PropertyInstance> operators;
           public Collection<PropertyInstance> getOperators() {
                return operators;
           public void setOperators(Collection<PropertyInstance> operators) {
                this.operators = operators;
      public class B extends RulesPropertiesSpecification {
      I'm trying to implement a check that would allow me to test if operators has annotation X defined for class B. How can access the annotation of the private data member?

      I've tried things like :
      private static boolean isAnnotationAccepted(Object bean, String fieldName, Class<? extends Annotation> annotationClass) throws SecurityException, NoSuchFieldException {
                Field field = bean.getClass().getField(fieldName);
                return (field.getAnnotation(annotationClass) != null) ? true : false;
      but this failed with a NoSuchFieldException.

      Help is appreciated.