[TIL]Android Annotations

mandoofu·2024년 10월 18일

안드로이드

목록 보기
17/20
post-thumbnail

Annotations

  • 코틀린 컴파일러 또는 런타임에 문법 에러등을 체크하기 위한 정보 제공

    • @Deprecated, @SuppressWarnings, @get:IntRange등등
  • IDE나Code Build (Compileor Runtime)시P/J에코드Add-On

    • Dependency Injection Annotation 등, Dagger-Hilt
  • Runtime 시에 특정기능을 실행하는 용도

    • Aspect-Oriented Programming 등
  • Meta Annotation

    • Annotation을 위한 Annotation 정보를제공
  • Custom Annotation

    • Kotlin Reflection을 이용한 Annotation (KAPT, KSP)
  • @Deprecated

    • API 나 라이브러리의 효용가치가 떨어졌음을 의미할 때 선언
    • 컴파일 시 compiler warnings 발생
  • @SuppressWarnings(“all”)

    • 컴파일 경고를 무시 할 때 사용
    • all : 모든 경고를 무시

Meta Annotations

  • Meta Annotaion을 이용해 개발자는 Custom Annotation을 만듨 ㅜ있다

  • compile-time : 유효성 체크 코드 생성 & 코드 검증 코드 생성

  • runtime : MetaData를 이용한 Application Code Add On

  • @Retention Annotation : Annotation 이 동작 해야 하는 곳을 정의

    • AnnotationRetention.RUNTIME
      • compile time + binary 에포함 reflection 을 이용해 접근 가능
    • AnnotationRetention.BINARY
      • compile time + binary 에 포함되나 reflection 접근 불가
    • AnnotationRetention.SOURCE
      • only compile time (컴파일이 끝나면 코드 없어짐)
    • AnnotationRetention.TYPE -> 어디서나 사용가능
  • @Target : enum AnnotationTarget

    • Annotation 적용할 위치를 결정
      • CLASS //Class, interface, object 에 사용 가능
      • ANNOTATION_CLASS// Class 에만 사용 가능
      • TYPE_PARAMETER
      • PROPERTY : 속성에만
      • FIELD : Field, including property's backing field
      • CONSTRUCTOR
      • FUNCTION//오직 함수에만
  • Android Module Kinds

    • Application
      • app 모듈
      • apk생성
    • Android Library
      • app 모듈에 종속
      • aar생성
    • kotlin/Java Library
      • kotlin/Java code
      • jar생성

0개의 댓글