Home  >  Article  >  Java  >  How to use annotations in java8

How to use annotations in java8

WBOY
WBOYforward
2023-05-01 11:58:061719browse

1. Define packaging comments, including an array of actual comments.

@interface Hints {
    Hint[] value();
}
 
@Repeatable(Hints.class)
@interface Hint {
    String value();
}

2. Annotation container.

@Hints({@Hint("hint1"), @Hint("hint2")})
class Person {}

3. Repeatable annotations. The java compiler can automatically set @Hint internally. This is important for reading annotation information via reflection.

@Hint("hint1")
@Hint("hint2")
class Person {}

The above is the detailed content of How to use annotations in java8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete