java反射创建类的三种方式

2021-03-28 00:00:00 创建 反射 三种

实体类



public class Student {
    public String name;
    private Integer age;
    private String sex;

    public Student() {
        System.out.println("构造器被调用");
    }

    public Student(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    public void eat(){
        System.out.println("吃饭");
    }
}
 Class.forName("com.xxx.domain.Student");// froName方法
 Class stu2 =   Student.class;// .class
 Student student1 = new Student();
 Class<? extends Student> aClass1 = student1.getClass(); // getClass方法

    原文作者:qq_57398284
    原文地址: https://blog.csdn.net/qq_57398284/article/details/123453735
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章