课后知识点回顾十三 反射
来源:互联网 发布:如何查本机mac地址 编辑:程序博客网 时间:2024/06/05 00:28
反射:通过获得class来拿到属性,构造方法等。
//拿到实现的接口
Class clazz = Class.forName("RecflectDemo.Laolei");
/*Class[] c = clazz.getInterfaces();
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}*/
//继承的父类
/*Class superClass = clazz.getSuperclass();
System.out.println(superClass);*/
/* Constructor[] c = clazz.getConstructors();
System.out.println(12);
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
//拿到构造函数的参数类型
Class[] p = c[1].getParameterTypes();
for (int i = 0; i < p.length; i++) {
System.out.println(p[i]);
}
//拿到所有的方法
Method[] m = clazz.getMethods();*/
//拿到属性
Field[] f = clazz.getDeclaredFields();
for (int i = 0; i < f.length; i++) {
System.out.println(f[i]);
}
//拿到实现的接口
Class clazz = Class.forName("RecflectDemo.Laolei");
/*Class[] c = clazz.getInterfaces();
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}*/
//继承的父类
/*Class superClass = clazz.getSuperclass();
System.out.println(superClass);*/
/* Constructor[] c = clazz.getConstructors();
System.out.println(12);
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
//拿到构造函数的参数类型
Class[] p = c[1].getParameterTypes();
for (int i = 0; i < p.length; i++) {
System.out.println(p[i]);
}
//拿到所有的方法
Method[] m = clazz.getMethods();*/
//拿到属性
Field[] f = clazz.getDeclaredFields();
for (int i = 0; i < f.length; i++) {
System.out.println(f[i]);
}
0 0
- 课后知识点回顾十三 反射
- 知识点课后回顾1
- 知识点课后回顾2
- 课后知识点回顾四 异常
- 课后知识点回顾五 线程
- 课后知识点回顾八 泛型
- 课后知识点回顾十一 File
- 课后知识点回顾十二 流
- 课后知识点回顾七 日期的格式
- 课后知识点回顾九 集合1
- 课后知识点回顾十 集合2
- 课后知识点回顾十四 网络编程1
- 课后知识点回顾十五 网络编程2
- java反射知识点简单回顾
- 知识点回顾
- 知识点回顾
- 知识点回顾
- 知识点回顾
- LPC824 使用FlashMagic 下载程序
- 手机卫士—检测SIM卡
- JAVA进阶----ThreadPoolExecutor机制
- 指针
- java学习笔记(三)之面向对象
- 课后知识点回顾十三 反射
- 手机卫士—远程锁屏
- JSP include parm动作
- java异常
- HR不要视员工“裸辞”为小事
- ubuntu 11.10 更新源source.list
- Java网络编程_基于TCP协议的网络编程(三)
- Udacity DEEPLEARNING 学习笔记 L2 DEEP NEURAL NETWORK
- NGUI|如何做出用鼠标滚动切换武器的效果