[JavaSE] annotation-custom annotation and javase annotation Customization
Annotation classification:
Source code annotation
@ Override annotated with JDK during compilation
@ Autowired of Spring annotation during runtime
Syntax requirements for custom annotations
① Use the @ interface keyword to define the Annotation
② The Member is executed without any parameters or exceptions.
③ You can use defaut to specify a default value for the member.
④ The member type is restricted, including the original type and String Class Annotation Enumberation
⑤ If the annotation has only one member, the member name must be named value (). during use, the member name and value assignment number (=) can be ignored)
⑥ The annotation class can have no members, which is called the identifier annotation.
Package com. tsh. ano; import java. lang. annotation. documented; import java. lang. annotation. elementType; import java. lang. annotation. inherited; import java. lang. annotation. retention; import java. lang. annotation. retentionPolicy; import java. lang. annotation. target; // meta annotation @ Target ({ElementType. METHOD, ElementType. TYPE}) // scope @ Retention (RetentionPolicy. RUNTIME) // life cycle @ Inherited // can be Inherited @ incluented // generate document public @ interface Description {String desc (); String author (); int age () default 18;} // use the annotation class DescAnoDemo {@ Description (author = "taoshihan", desc = "hahaha") void show (){}}
Meta annotation: Annotation
Use custom annotations
Parse Annotation