Annotations are like meta-tags that you can add to your code and apply to package declarations, type declarations, constructors, methods, fields, parameters and variables.
Simply speaking, an annotation is a mechanism for associating a meta-tag with program elements and allowing the compiler or the VM to extract program behaviors from these annotated elements and generate interdependent code when necessary.
Usually you need use @interface to define an annotation type, then annotate your codes using @MyAnnotation.
There are three annotation types:
- Marker type annotation has no elements, except the annotation name itself.
- Single-element, or single-value type, annotation provides a single piece of data only. This can be represented with a data=value pair or, simply with the value (a shortcut syntax) only, within parenthesis.
- Full-value type annotation has multiple data members. Therefore, you must use a full data=value parameter syntax for each member.
- Simple
- Meta
- Override
- Deprecated
- SuppressWarnings
- Target
- Retention
- Documented
- Inherited
No comments:
Post a Comment