1 Star 0 Fork 0

yirenzhixia/JavaBasic

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
JavaBasic.java 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
yirenzhixia 提交于 2018-08-27 10:33 +08:00 . Java基础代码
import annotation.Father;
import annotation.Son;
import annotation.TestAn;
import exception.Test;
import genericity.Xm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Java基础
*
* @author ZwT
* @date 2018-05-08 13:29
**/
@SuppressWarnings("deprecation")
public class JavaBasic {
public static void main(String[] args) throws Exception{
Class clazz = Class.forName("annotation.Son");
if(clazz.isAnnotationPresent(TestAn.class)){
TestAn testAn = (TestAn) clazz.getAnnotation(TestAn.class);
System.out.println(testAn.id());
System.out.println(testAn.name());
}
Field field = clazz.getDeclaredField("age");
field.setAccessible(true);
TestAn testAn1 = field.getAnnotation(TestAn.class);
System.out.println(testAn1.id());
Constructor constructor = clazz.getConstructor();
TestAn testAn2 = (TestAn) constructor.getAnnotation(TestAn.class);
System.out.println(testAn2.id());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zwtxm/JavaBasic.git
git@gitee.com:zwtxm/JavaBasic.git
zwtxm
JavaBasic
JavaBasic
master

搜索帮助