http://en.wikipedia.org/wiki/Java_annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated. Unlike Javadoc tags, Java annotations can be reflective in that they can be embedded in class files generated by the compiler and may be retained by the Java VM to be made retrievable at run-time.
http://www.gurubee.net/display/WEBSTUDY/Annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated. Unlike Javadoc tags, Java annotations can be reflective in that they can be embedded in class files generated by the compiler and may be retained by the Java VM to be made retrievable at run-time.
http://www.gurubee.net/display/WEBSTUDY/Annotation
Annotation 이란
- 메타데이터, 한 마디로 데이터의 데이터다
- 어노테이션이 나오기 전까지 메타데이터는 프로퍼티 파일과 XML파일을 활용하였다.
- 어노테이션은 주로 데이터를 문서화하거나, 컴파일 타임이나 런타임시에 원하는 동작을 수행할 수 있도록 하는 데 사용된다.
- 닷넷프레임워크 1.0에서 어트리뷰트라는 기능을 제공하자, 자바에서 어노테이션을 통한 메타데이터 활용 기술을 제공했다.
Annotation의 장점
- 코드의 가독성 증대
- 관련 코드 곁에 메타데이터를 설정할 수 있으므로 코드의 가독성 증대 된다.
- 개발 효율성 증대
- 복잡한 XML 스키마를 파악하지 않아도 되며, 개발시 개발 툴과 컴파일러의 도움을 받을 수 있으므로 개발 효율성이 증대 된다.
- 별도의 파서를 적용하지 않고도 간단히 런타임 시에 활용할 수 있는 편리함이 있다.
- JUnit, Framework, Permission Module 에서 사용
Annotation을 반대하는 사람들의 의견
- 메타정보와 소스의 결합자체를 못마땅하다.
- 메타데이터는 그 자체로 코드에 독립적이어야 하며 한 곳에 모여져서 어플리케이션의 구성을 한눈에 알 수 있어야 바람직하다는 주장.
- 어노테이션은 코드를 이용해서 검증하는게 가능하지만 XML의 DTD나 스키마를 이용하는 검증 방식에 비해서 훨씬 불편하다.
Annotation의 단점
- 어노테이션 처리시 리플렉션을 통해 해당 클래스를 분석해야 하는 오버헤드가 있다.
- XML 파일을 이용하는 방법도 오버헤드가 있으므로, 경우에 따라서 어노테이션이 더 빠를 수도 있음.
- 어노테이션은 모듈이나 어플리케이션 전반적인 메타데이터를 설정할 수 없다.
- 어노테이션의 범위는 클래스나 패키지 레벨로 한정되기 때문에 여러 클래스에 걸친 공통적인 설정이나 모듈레벨 설정이 어렵다.
- 웹 어플리케이션 개발시 서블릿 필터나, 인터셉터를 이용해서 문제 해결이 가능함.
'program language > java' 카테고리의 다른 글
log4j 설정 (1) | 2012.04.09 |
---|---|
junit4 정리 (0) | 2012.04.04 |
JAX-RS: Java API for RESTful Web Services (0) | 2012.03.26 |
JDO(Java Data Object) (0) | 2012.03.15 |
JSR(Java Specification Requests),JCP(Java Community Process) (1) | 2012.03.06 |