skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, September 20, 2012

Java Reflection Field with Annotation

Posted by Admin at 12:19 PM – 0 comments
 

Java Reflection Field with Annotation


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 {
}



Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger