Get list of fields with annotation, by using reflection

前端 未结 2 1482
情书的邮戳
情书的邮戳 2020-12-05 09:42

I create my annotation

public @interface MyAnnotation {
}

I put it on fields in my test object

public class TestObject {

          


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 09:49

    You need to mark the annotation as being available at runtime. Add the following to your annotation code.

    @Retention(RetentionPolicy.RUNTIME)
    public @interface MyAnnotation {
    }
    

提交回复
热议问题