Study - Annotations
                                            
                                                
                                                
                                                
                                                
                                                
                                                 2323 단어  JavaannotationsstudyJava
                    
정의
- 사전적 의미: 주석
- metadata의 형태
- program에 대한 데이터를 제공
용도
- Information for the compiler: compiler가 error나 warning을 발견할 수 있도록 사용됨
- Compile-time and deployment-time processing: software tool들이 annotation을 이용해 code, XML files 등을 생성 가능
- Runtime processing: Runtime에서도 사용될 수 있음
형태
- @{Annotation name}을 변수, 함수에 붙여 사용- 
- class instance 생성문 (new class()), type cast, implements절, exception throws 선언문에 사용 가능
 
@Override
void myMethod() {...}
- annotation에 elements를 추가 가능
- 이름을 명시 안할 수도 있음
 
@Author(
   name = "Benjamin Franklin",
   date = "3/27/2003"
)
class MyClass() { ... }
@SuppressWarnings("unchecked")
void myMethod() { ... }
- 여러 annotaion 설정 가능
- default값 설정 가능
선언 방법
- 선언 예시
@interface ClassPreamble {
   String author();
   String date();
   int currentRevision() default 1;
   String lastModified() default "N/A";
   String lastModifiedBy() default "N/A";
   // Note use of array
   String[] reviewers();
}
- 사용 예시
@ClassPreamble (
   author = "John Doe",
   date = "3/17/2002",
   currentRevision = 6,
   lastModified = "4/12/2004",
   lastModifiedBy = "Jane Doe",
   // Note array notation
   reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {
// class code goes here
}
Predefined Annotation Types
- @Deprecated
- @Override
- @SuppressWarnings
- @NonNull String str;
- ...
Meta Annotation
@Target
- 적용 위치 설정 (default: 전체)
- TYPE, ANNOTATION_TYPE, METHOD, PACKAGE...
@Retention
- SOURCE, CLASS, RUNTIME
- 영향을 미치는 시점을 설정
출처
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여(Study - Annotations), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@taesunny/Java-Study-Annotations
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
- Information for the compiler: compiler가 error나 warning을 발견할 수 있도록 사용됨
- Compile-time and deployment-time processing: software tool들이 annotation을 이용해 code, XML files 등을 생성 가능
- Runtime processing: Runtime에서도 사용될 수 있음
형태
- @{Annotation name}을 변수, 함수에 붙여 사용- 
- class instance 생성문 (new class()), type cast, implements절, exception throws 선언문에 사용 가능
 
@Override
void myMethod() {...}
- annotation에 elements를 추가 가능
- 이름을 명시 안할 수도 있음
 
@Author(
   name = "Benjamin Franklin",
   date = "3/27/2003"
)
class MyClass() { ... }
@SuppressWarnings("unchecked")
void myMethod() { ... }
- 여러 annotaion 설정 가능
- default값 설정 가능
선언 방법
- 선언 예시
@interface ClassPreamble {
   String author();
   String date();
   int currentRevision() default 1;
   String lastModified() default "N/A";
   String lastModifiedBy() default "N/A";
   // Note use of array
   String[] reviewers();
}
- 사용 예시
@ClassPreamble (
   author = "John Doe",
   date = "3/17/2002",
   currentRevision = 6,
   lastModified = "4/12/2004",
   lastModifiedBy = "Jane Doe",
   // Note array notation
   reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {
// class code goes here
}
Predefined Annotation Types
- @Deprecated
- @Override
- @SuppressWarnings
- @NonNull String str;
- ...
Meta Annotation
@Target
- 적용 위치 설정 (default: 전체)
- TYPE, ANNOTATION_TYPE, METHOD, PACKAGE...
@Retention
- SOURCE, CLASS, RUNTIME
- 영향을 미치는 시점을 설정
출처
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여(Study - Annotations), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@taesunny/Java-Study-Annotations
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
@{Annotation name}을 변수, 함수에 붙여 사용- class instance 생성문 (new class()), type cast, implements절, exception throws 선언문에 사용 가능
@Override
void myMethod() {...}- 이름을 명시 안할 수도 있음
@Author(
   name = "Benjamin Franklin",
   date = "3/27/2003"
)
class MyClass() { ... }
@SuppressWarnings("unchecked")
void myMethod() { ... }- 선언 예시
@interface ClassPreamble {
   String author();
   String date();
   int currentRevision() default 1;
   String lastModified() default "N/A";
   String lastModifiedBy() default "N/A";
   // Note use of array
   String[] reviewers();
}- 사용 예시
@ClassPreamble (
   author = "John Doe",
   date = "3/17/2002",
   currentRevision = 6,
   lastModified = "4/12/2004",
   lastModifiedBy = "Jane Doe",
   // Note array notation
   reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {
// class code goes here
}Predefined Annotation Types
- @Deprecated
- @Override
- @SuppressWarnings
- @NonNull String str;
- ...
Meta Annotation
@Target
- 적용 위치 설정 (default: 전체)
- TYPE, ANNOTATION_TYPE, METHOD, PACKAGE...
@Retention
- SOURCE, CLASS, RUNTIME
- 영향을 미치는 시점을 설정
출처
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여(Study - Annotations), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@taesunny/Java-Study-Annotations
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
@Target
- 적용 위치 설정 (default: 전체)
- TYPE, ANNOTATION_TYPE, METHOD, PACKAGE...
@Retention
- SOURCE, CLASS, RUNTIME
- 영향을 미치는 시점을 설정
출처
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여(Study - Annotations), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@taesunny/Java-Study-Annotations
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Author And Source
이 문제에 관하여(Study - Annotations), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@taesunny/Java-Study-Annotations저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)