본문
170427(목) - Repeating Annotations
Programming/Java 8 2017. 4. 27. 18:08
Repeating Annotations
standard annotation을 사용하는 곳이면 어디서나 annotation을 반복 가능하다.
@Schedule(dayOfMonth="last")
@Schedule(dayOfWeek="Fri", hour="23")
public void doPeriodicCleanup() { ... }@Alert(role="Manager")
@Alert(role="Administrator")
public class UnauthorizedAccessException extends SecurityException { ... }repeating annotation은 container annotation에 저장된다.
compiler를 실행하려면 코드에 두 가지의 추가적인 declaration이 필요
1. Declare a Repeatable Annotation type
주석 유형은 @repeatable meta-annotation에 지정 해줘야 한다.
import java.lang.annotation.Repeatable;
@Repeatable(Schedules.class)
public @interface Schedule {
String dayOfMonth() default "first";
String dayOfWeek() default "Mon";
int hour() default 12;
}2. Declare the Containing Annotation type
containing annotation은 배열형의 value 요소를 가져야 한다.
public @interface Schedules {
Schedule[] value();
}'Programming > Java 8' 카테고리의 다른 글
| 170427(목) - Method References (0) | 2017.04.27 |
|---|---|
| 170420(목) - Streams <Terminal Operations> (0) | 2017.04.20 |
| 170420(목) - Streams <Intermediate Operations> (0) | 2017.04.20 |
| 170420(목) - Streams <Laziness and Performance Optimization> (0) | 2017.04.20 |
| 170420(목) - Streams <Understanding Java 8 Streams API (0) | 2017.04.20 |
댓글