一、反射的概念解释:
写一个类是把各属性、各方法、各构造器包装成目标类的过程。反过来看,通过一个确切的类把里面的个属性、各方法、各构造器解析出来的过程则是反射。
二、反射举例分别获取类的构造器、属性、方法
构建一个Student类如下:
public class Student {
String name;
int age;
private char sex;
public Student()
{
System.out.println("this is the constructor of no variable");
}
public Student(String name)
{
this.name=name;
System.out.println("set name with"+name);
}
public Student(int age)
{
this.age=age;
System.out.println("set age with"+age);
}
private Student(char sex)
{
this.sex=sex;
System.out.println("set sex with"+sex);
}
public String GetName()
{
return name;