이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Target {
/**
* Returns an array of the kinds of elements an annotation type
* can be applied to.
* @return an array of the kinds of elements an annotation type
* can be applied to
*/
ElementType[] value();
}
이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Retention {
/**
* Returns the retention policy.
* @return the retention policy
*/
RetentionPolicy value();
}
@Retention은 해당 애노테이션이 언제까지 유지할지 알려주는 애노테이션이다.
그러므로 Retention 애노테이션에도
자기 자신이 어느 시점까지 유효한지를 명시해줘야한다.
@Retention(RetentionPolicy.RUNTIME)
Retention에는 3가지 속성이 있다.
SOURCE, CLASS, RUNTIME
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
/**
* Annotations are to be recorded in the class file by the compiler
* but need not be retained by the VM at run time.
* This is the default
* behavior.
*/
CLASS,
/**
* Annotations are to be recorded in the class file by the compiler and
* retained by the VM at run time, so they may be read reflectively.
*
* @see java.lang.reflect.AnnotatedElement
*/
RUNTIME
}
이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
사용하려는 애노테이션(=A)에
@Documneted를 메타 애노테이션으로 설정이 되어있다면
해당 애노테이션(=A)을 사용하는 애노테이션의 코드 문서에는
사용한 애노테이션(=A)이 노출된다.
이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
이 글의 코드 및 정보들은 강의를 들으며 정리한 내용을 토대로 작성하였습니다.
자바 파일을 클래스 파일로 만들 때
그 타이밍에 바이트 코드들을 조작하여
조작이된 바이트 코드를 생성해낸다.
이게 컴파일 타임에 AOP를 적용하는 방법이다.
A라는 클래스에 foo()라는 메소드가 있다.
그리고 Hello를 출력하는 Aspect가 있다.
여기서 foo()를 호출하면 Hello가 먼저 출력이 되야한다.
위와 같은 상황에 컴파일 타임에 AOP를 적용한다면
클래스 파일에 Hello를 출력하는 메소드가 같이 들어있게 된다.
컴파일 타임 시점에 AOP 적용 시 장단점
장점
단점