When are Java annotations executed?

后端 未结 7 2148
执念已碎
执念已碎 2021-02-06 04:12

I am just looking to write some annotation which can execute at runtime, before or immediately after a service method is invoked.

I don\'t know if they are executed at r

7条回答
  •  半阙折子戏
    2021-02-06 05:00

    Annotations are just markers. They don't execute and do anything.

    You can specify different retention policies:

    • SOURCE: annotation retained only in the source file and is discarded during compilation.
    • CLASS: annotation stored in the .class file during compilation, not available in the run time.
    • RUNTIME: annotation stored in the .class file and available in the run time.

    More here: http://www.java2s.com/Tutorial/Java/0020__Language/SpecifyingaRetentionPolicy.htm

提交回复
热议问题