(JAVA)reflect练习
生活随笔
收集整理的這篇文章主要介紹了
(JAVA)reflect练习
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
className = Student
methodName = student
import java.awt.*;
import java.io.FileReader;
import java.lang.reflect.Method;
import java.util.Properties;/*** @author Alina* @date 2022年01月08日 7:08 下午*/
public class ReflectPra {public static void main(String[] args) throws Exception{//創建鍵值對Properties pro = new Properties();//創建集合FileReader fileReader = new FileReader("config.txt");pro.load(fileReader);fileReader.close();System.out.println(pro);Class clazz = Class.forName(pro.getProperty("className"));Object obj = clazz.newInstance();Method method = clazz.getMethod(pro.getProperty("methodName"));method.invoke(obj);}
}
總結
以上是生活随笔為你收集整理的(JAVA)reflect练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Map 的Properties集合存储I
- 下一篇: docker如何配置阿里云加速器