1, in addition to the restrictions on the inheritance relationship (cannot add a generic declaration can not add extends inherit another interface), declared with @interface instead of interface, annotation type and ordinary interface no difference
2, the annotation type can contain multiple elements, defined by the method declaration form, the Declaration of these methods cannot have any parameters or type parameters, there is no method body; The method return value type can only be a base type, String, Class, Enum, annotation type, and array type, and arrays do not support multidimensional arrays. Note types can also have no elements. If the annotation type has only one element, which is generally named value (as the default value object for use), the default value is implemented by the method after the life defaults:
Public @interface Fuck {String me () The default "author"; int you () default 2; class<?> him () default integer.class; String[] All () The default {"You", "Me"};}
Value at the time:
Public @interface Comeon {String value () Default "";}
Example:
@ComeOn ("Shit") @Fuck (Me = "Wang8dan", you = +, all = {"SB", "XB", "DB"}) public void Test () {System.out.println ("OK");}
3, the annotations are divided into two categories:
1) meta-Annotations for configuration annotations
(1) Enum type Elementtype:type (type declaration), Annotation_type (annotation type declaration), package (packet Declaration), CONSTRUCTOR (constructor Declaration), field (domain declaration), method (methods Declaration) , PARAMETER (method parameter declaration), local_variable (local variable declaration), where each type represents the usage scope of this annotation
(2) Rentention:source (annotations will only appear in the source code, will not appear in the bytecode), CLASS (annotations are reserved to bytecode, but any case declared on the local variables only appear in the source code), Runtime (annotation runtime is available, can be called through the reflection API)
(3) Inherited, describes the class that uses this declaration, and its subclasses inherit the above declaration
2) General notes
(1) Override
(2) Deprecated
(3) Suppresswarning: Prevent certain warnings thrown at compile time, when used such as: @SuppressWarning ("unchecked")
Java 8 angle View annotation type