annotation
sample
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface NewIntent {
}
ElementType
public enum ElementType {
TYPE, //If you want to annotate class, interface, enum..
FIELD, //If you want to annotate field (includes enum constants)
METHOD, //If you want to annotate method
PARAMETER, //If you want to annotate parameter
CONSTRUCTOR, //If you want to annotate constructor
LOCAL_VARIABLE, //..
ANNOTATION_TYPE, //..
PACKAGE, //..
TYPE_PARAMETER, //..(java 8)
TYPE_USE; //..(java 8)
private ElementType() {
}
}
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)