Java reflection mechanism to instantiate objects

//通过反射机制,获取Class ,通过Class来实例化对象
Class C = Class.forName("com.java.bean.User");
object obj = c.newInstance();//调用无参数构造方法,实例化

Advantages : By reading the configuration file, a set of codes can be used to create different objects, and the principle of compound opening and closing

User user=new User();

Guess you like

Origin blog.csdn.net/ResumeProject/article/details/114394972