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;
import org.junit.Test;
public class UserBean {
@UserBeanAnno(desc="xxx")
private int id = 38;
@UserBeanAnno(remark="yyy")
private String name = "wangdonghua";
@Test
public void test()throws Exception{
Class cls = this.getClass();
Field[] fields = cls.getDeclaredFields();
for(Field field:fields){
UserBeanAnno anno = field.getAnnotation(UserBeanAnno.class);
System.out.println(field.get(this));
System.out.println(anno.desc());
System.out.println(anno.remark());
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface UserBeanAnno{
String desc() default "desc";
String remark() default "remark";
}
}