myreflection.java
来自「这是学习java程序设计的视频的最后一部分教材」· Java 代码 · 共 38 行
JAVA
38 行
package com.langsin.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
public class MyReflection
{
public static void main(String[] args) throws Exception
{
MyTest myTest = new MyTest();
Class<MyTest> c = MyTest.class;
Method method = c.getMethod("output",new Class[]{});
if(method.isAnnotationPresent(MyAnnotation.class))
{
method.invoke(myTest,new Object[]{});
MyAnnotation myAnnotation = method.getAnnotation(MyAnnotation.class);
String hello = myAnnotation.hello();
String world = myAnnotation.world();
System.out.println(hello);
System.out.println(world);
}
Annotation[] annotations = method.getAnnotations();
for(Annotation annotation : annotations)
{
System.out.println(annotation.annotationType().getName());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?