![image-20230830212918793](https://img-blog.csdnimg.cn/img_convert/82561f3d3c4a2c39a00f6d35bd03efd0.png)
![image-20230830212927463](https://img-blog.csdnimg.cn/img_convert/10e4f4200dffe1a17c23eada53cee868.png)
![image-20230830213014224](https://img-blog.csdnimg.cn/img_convert/f034e55322e0a0148a19a65e492e4d0e.png)
![image-20230830213028629](https://img-blog.csdnimg.cn/img_convert/2c7130a34d863e0ef26e7c82ddeac0b1.png)
public class Reflection01 {
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(new FileInputStream("src\\re.properties"));
String classfullpath = properties.get("classfullpath").toString();
String methodName = properties.get("method").toString();
Class cls = Class.forName(classfullpath);
Object o = cls.newInstance();
System.out.println("o 的运行类型=" + o.getClass());
Method method1 = cls.getMethod(methodName);
System.out.println("=============================");
method1.invoke(o);
Field nameField = cls.getField("age");
System.out.println(nameField.get(o));
Constructor constructor = cls.getConstructor();
System.out.println(constructor);
Constructor constructor2 = cls.getConstructor(String.class);
System.out.println(constructor2);
}
}
![image-20230830213623656](https://img-blog.csdnimg.cn/img_convert/f520a07533501b01bd22707e88c10501.png)
Class 类
![image-20230830213652341](https://img-blog.csdnimg.cn/img_convert/d693c8fd48312cb0841ace3772726b54.png)
![image-20230830213659367](https://img-blog.csdnimg.cn/img_convert/86fb29575ab9dac242d13ba23069ed1b.png)
![image-20230830213724777](https://img-blog.csdnimg.cn/img_convert/6f192400bb16a7b0e411e9c83ab89911.png)
通过反射获取类的结构信息
![image-20230830214200452](https://img-blog.csdnimg.cn/img_convert/9163d39cc567b9fe64da62c3fbefb589.png)
- java.lang.reflect.Field 类
![image-20230830214257057](https://img-blog.csdnimg.cn/img_convert/287f05596c81fc397dd9b70b9388c184.png)
- java.lang.reflect.Method 类
![image-20230830214317493](https://img-blog.csdnimg.cn/img_convert/b1308f872d0f7b1a8b537e69d409d7e2.png)
- java.lang.reflect.Constructor 类
![image-20230830214422493](https://img-blog.csdnimg.cn/img_convert/7f1b5f46cce9e8f04bdbc094a615d5b7.png)
通过反射创建对象
![image-20230830214557329](https://img-blog.csdnimg.cn/img_convert/9845d455effd8a4d3e4815bec97305e6.png)
通过反射访问类中的成员
![image-20230830214741315](https://img-blog.csdnimg.cn/img_convert/ebde21d52b62fa714962ffb607ab1785.png)
- 访问方法ReflecAccessMethod.java
![image-20230830214834901](https://img-blog.csdnimg.cn/img_convert/5a8f704ac2c5d2bc12d20a43ff20b0dd.png)