getAnnotations() is empty

前端 未结 1 1047
死守一世寂寞
死守一世寂寞 2021-02-18 23:26

I would like to use annotations in my application. For this reason I create \"hello world\" for annotations:

follows example:

public class HelloAnnotatio         


        
相关标签:
1条回答
  • 2021-02-18 23:51

    Add the following to your annotation:

        @Retention(RetentionPolicy.RUNTIME)
    

    From the javadoc for @Retention:

    the retention policy defaults to RetentionPolicy.CLASS

    From the javadoc for RetentionPolicy:

    • CLASS
      • Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.
    • RUNTIME
      • Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.
    • SOURCE
      • Annotations are to be discarded by the compiler.
    0 讨论(0)
提交回复
热议问题