How to extend Java annotation?

前端 未结 6 1247
闹比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:49

    From Java language specification, Chapter 9.6 Annotation Types:

    No extends clause is permitted. (Annotation types implicitly extend annotation.Annotation.)

    So, you can not extend an Annotation. you need to use some other mechanism or create a code that recognize and process your own annotation. Spring allows you to group other Spring's annotation in your own custom annotations. but still, no extending.

提交回复
热议问题