Programming/Java

Reflection

byeong07 2019. 3. 3. 21:46

- Reflection




* Reflection에 필요한 클래스는 java.lang.reflect 패키지에서 제공

Reflection은 객체를 통해 클래스의 정보를 분석하는 프로그램

* 컴파일 타임에 인터페이스
필드메소드의 이름을 알지 못해도 실행 중에 접근 가능


Reflection을 사용하는 것은 Composition과 함께 사용되어 다형성을 구현하기 위해 사용





* @Target Annotationmethod에 적용한다는 의미


*
@Retention Annotationruntime  시까지 어노테이션 정보를 유지

* 사용자 정의
AnnotationPrintAnnotation을 생성





* annotation을 정의한 classPrintAnnotation을 적용


*
@Retention Annotationruntime  시까지 어노테이션 정보를 유지

* 사용자 정의
AnnotationPrintAnnotation을 생성