- 获取类有三种方法
实体类和接口
public interface Person {
public void sayHi();
}
public class Student implements Person{
private String id;
private String name;
private int age;
public int sex=1;
/*get和set方法省略*/
}
Class c1 = Student.class;
Class c2=Class.forName("com.study.reflect.Student");
Class c3=new Student().getClass();
System.out.println(c1==c2);
System.out.println(c1==c3);
输出:true true
为什么都是true:
时间: 2025-01-22 10:35:16