📄 testannotation.java
字号:
/*
* TestAnnotation.java
*
* Created on 2007年9月19日, 下午11:32
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package newAnnotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
*
* @author Administrator
*/
@MyAnnotation(@Name(first="kevin",last="li"))
public class TestAnnotation {
/** Creates a new instance of TestAnnotation */
public TestAnnotation() {
}
public void test(){
}
public static void main(String[] args) {
try {
(new TestAnnotation()).test();
Class c = TestAnnotation.class;
Method m = c.getMethod("test");
System.out.println(m.isAnnotationPresent(MyAnnotation.class));
AnnotatedElement target = TestAnnotation.class;
MyAnnotation ma = target.getAnnotation(MyAnnotation.class);
Name name = ma.value();
String first = name.first();
String last = name.last();
System.out.printf("first:%s, second:%s",first,last);
} catch (SecurityException ex) {
ex.printStackTrace();
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -