When are Java annotations executed?

后端 未结 7 1984
执念已碎
执念已碎 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:03

    Actually, when you define an annotation, you must specify the parameter @Retention, which defines whether the annotation is available in the source code (SOURCE), in the class files (CLASS), or at run time (RUNTIME).

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

提交回复
热议问题