How to extend Java annotation?

前端 未结 6 1251
闹比i
闹比i 2020-12-09 01:08

In my project I use pre-defined annotation @With:

@With(Secure.class)
public class Test { //....

The source code of @Wit

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 01:43

    To expand on Muhammad Abdurrahman's answer--

    @With(Secure.class)
    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Secure {
    
    }
    

    This does not work by default but you can use it in conjunction with Spring's AnnotationUtils.

    See this SO answer for an example.

提交回复
热议问题