Friday, February 10, 2006

Inside JavaSE 5.0 Part I

About Annotation

What's is annotation?

Annotation is a metadata or data of data. In Java that means the data of those Java elements.

JavaSE 5.0 including 7 build-in annotations:

  • java.lang.Override (@Override)
    Means this method is overriding a method in superclass
  • java.lang.Deprecated (@Deprecated)
    Means this method is already deprecated, when u use it, the compiler will throw out a warning message.
  • java.lang.SuppressWarning (@SuppressWarning)
    Means some kind of warning specified by SuppressWarning will be suppressed, and all the specifed warning generated by the child element of which marked @SuppressWarning will also be suppressed.
  • java.lang.annotation.Documented (@Documented)
    Means the element annotated are to be documented by javadoc.
  • java.lang.annotation.Inherited (@Inherited)
    Means the annotation type is automaticlly inherited. When those class did not used this annotation type to be queried, the superclass will also be quired
  • java.lang.annotation.Retention (@Retention)
    Stands for a restriction of annotation retention. Could be SOURCE or CLASS or RUNTIME. Default is CLASS
  • java.lang.annotation.Target (@Target)
    Stands for a restriction of element that can comsume this annotation type. Default is full element.

What's the benifits from annotation?

In general, metadata annotation benifits fall into 3 categories:

  • Documentation
  • Compiler checking
  • Code analysis

Annotation is useful to JavaEE and similar to XDoclet, but it's now fully supported by JRE.

No comments:

Post a Comment