annotation

sample

  1. @Retention(RetentionPolicy.SOURCE)
  2. @Target(ElementType.TYPE)
  3. public @interface NewIntent {
  4. }

ElementType

  1. public enum ElementType {
  2. TYPE, //If you want to annotate class, interface, enum..
  3. FIELD, //If you want to annotate field (includes enum constants)
  4. METHOD, //If you want to annotate method
  5. PARAMETER, //If you want to annotate parameter
  6. CONSTRUCTOR, //If you want to annotate constructor
  7. LOCAL_VARIABLE, //..
  8. ANNOTATION_TYPE, //..
  9. PACKAGE, //..
  10. TYPE_PARAMETER, //..(java 8)
  11. TYPE_USE; //..(java 8)
  12. private ElementType() {
  13. }
  14. }

Element

Element represents a program element such as package, class, or methods. We work with elements to read its properties while processing.

  • TypeElement - represents a class or interface
  • VariableElement - represents a field
  • ExecutableElement - It represents a method

RetentionPolicy

  • SOURCE — analyses by compiler and never stored
    • will be removed when the code is compiled
  • CLASS — stored into class file and not retained in runtime
    • will be preserved in the compiled bytecode in addition to the source code
  • RUNTIME — store into class file and usable in runtime(by reflection)