Stuff related to Java Annotations and Annotation Processing
@Retention(RUNTIME) //RetentionPolicy
@Target(TYPE) //ElementType
public @interface MyAnnot {
boolean value() default false;
String name();
}
CLASS |
Compiled into .class No Reflection
|
RUNTIME |
Available for Reflection
|
SOURCE |
Only in Source Dropped for Compilation
|
TYPE |
Class, Interface, Enum
|
FIELD |
Class fields
|
METHOD |
Methods no Constructor
|
PARAMETER |
Any Param of a Method/Constructor
|
CONSTRUCTOR |
Only Constructors
|
LOCAL_VARIABLE |
only Local Vars
|
ANNOTATION_TYPE |
valid for other Annotations
|
PACKAGE |
Annotation for Package
|
PACKAGE annotations should only be in package-info.java
Class
getAnnotation(Class<A> aClass) |
in this class or from parent
|
getDeclaredAnnotation(Class<A> aClass) |
only declared in this class
|
getAnnotations() |
array of Annotations
|
getDeclaredAnnotations() |
array of Annotations
|
get[Declared]Field(String name) |
extracts a
Field |
get[Declared]Method(String name, Class<?>... parameterTypes) |
extracts a
Method |
getConstructors() |
extracts an Array of
Constructor |
get[Declared]Fields() |
extracts an Array of
Field |
get[Declared]Methods() |
extracts an Array of
Method |
getDeclared... always points to exactly this Object only including private, without Declared any super can also match but only public ones.
Field information
getName() |
|
getType() |
|
getModifiers() |
|
get(Object obj) |
extract field value from
obj |
set(Object obj, Object val) |
set field to value
|
getInt(obj), setInt(obj, val)
getName() |
|
getParameterTypes() |
Class Array of Types |
getReturnType() |
|
invoke(Object obj, Object... args) |
Call Method
|
Object.class.newInstance() |
utilizes Default Constructor of an Class object
|
const.newInstance(Object.... args) |
utilizes one of the extracted Constructors
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.