Source Code : Field with annotations

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Field with annotations

       
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

public class DataBeanTest {

  public static void main(String[] args) {
    Class d = DataBean.class;

    Field fs[] = d.getFields();
    for (Field f : fs) {
      System.out.println(f);

      Annotation a = f.getAnnotation(DataField.class);

      if (a != null) {
        System.out.println(f.getName());
      }
    }
  }
}

class DataBean {
  @DataField
  public String name;

  @DataField
  public String data;

  public String description;
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface DataField {
}

   
    
    
    
    
    
    
  

Thank with us