Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

애너테이션 #15

Open
bong01 opened this issue Mar 29, 2022 · 1 comment
Open

애너테이션 #15

bong01 opened this issue Mar 29, 2022 · 1 comment

Comments

@bong01
Copy link
Member

bong01 commented Mar 29, 2022

  • 애너테이션의 강점은 추가적으로 필요한 처리를 비즈니스 로직에 영향을 주지 않은 채로 할 수 있다는 데 있다.
  • 시스템 설정과 같은 부가적인 사항들을 애너테이션을 통해 구현할 수 있도록 위임하는 것이다.
  • 애너테이션을 통해 클래스 자체에서는 비즈니스 로직에 집중할 수 있고, 적절한 관심사의 분리가 이루어진다.

애너테이션 정의

  • @interface를 통해서 타입 선언을 한다.
public @interface MyAnnotation {
}
  • 메타 애너테이션으로 @Target@Rentention을 작성해주어야 한다.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}

@Target
: 애너테이션이 적용 가능한 대상

ex. TYPE, ANNOTATION_TYPE, FIELD, CONSTRUCTOR, METHOD

@Rentention

: 애너테이션이 유지되는 기간

ex. SOURCE, CLASS, RUNTIME

  • SOURCE: 소스파일에만 존재, 컴파일 후 클래스 파일에서는 사라짐
  • CLASS: 클래스 파일까지 존재, 런타임 시 사라짐 (Default)
  • RUNTIME: 런타임까지 존재, 리플렉션을 통해 애너테이션 정보를 사용 가능

참고: https://joel-dev.site/83?category=1018629

@ksi05503
Copy link
Contributor

기본 애너테이션에 들어가보면 저런 Retention 이나 Target이 들어가있다니, 자주 확인해야겠다
애너테이션도 인터페이스 느낌
애너테이션 어떨때 사용자정의로 활용하는지 찾아봐야겠군

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants