forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnnotationTest.java
More file actions
28 lines (23 loc) · 766 Bytes
/
AnnotationTest.java
File metadata and controls
28 lines (23 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package JavaBasic;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/**
* @Classname AnnotationTest
* @Description 自定义Annotation
* @Date 19-7-1 下午11:22
* @Created by mao<tianmao818@qq.com>
*/
public class AnnotationTest {
@TestAnnotation(value = "测试方法")
public static void main(String[] args){
Class c=AnnotationTest.class;
Method[] methods=c.getDeclaredMethods();
for (Method method:methods){
Annotation[] annotations=method.getDeclaredAnnotations();
for(Annotation annotation:annotations){
TestAnnotation testAnnotation=(TestAnnotation)annotation;
System.out.println(testAnnotation.value());
}
}
}
}