How to get annotations of a member variable?

前端 未结 8 2142
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 00:29

I want to know a class\'s some member variable\'s annotations , I use BeanInfo beanInfo = Introspector.getBeanInfo(User.class) to introspect a class , and use <

8条回答
  •  孤街浪徒
    2020-11-29 00:55

    Everybody describes issue with getting annotations, but the problem is in definition of your annotation. You should to add to your annotation definition a @Retention(RetentionPolicy.RUNTIME):

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.FIELD)
    public @interface MyAnnotation{
        int id();
    }
    

提交回复
热议问题