📄 test2.java
字号:
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class test2
{
public static void main( String[] args ) throws Exception
{
//access the class annotation
Class<MyClass> cls = MyClass.class;
System.out.println( cls.getAnnotation( HelloTag.class ) );
//access the constructor annotation
Constructor<MyClass> con = cls.getConstructor((Class[]) null);
System.out.println(con.getAnnotation(HelloTag.class));
//access the method annotation
Method mth = cls.getMethod( "show" );
System.out.println(mth.getAnnotation(HelloTag.class));
//access the field annotation
Field field = cls.getField("name");
System.out.println(field.getAnnotation(HelloTag.class));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -