java反射

一、反射概述

 

 

二、反射的相关操作

1、获取Class类对象

示例:

学生类:

package com.itbianma;

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

    public Student() {
    }

    public Student(String name, String address, Integer age) {
        this.name = name;
        this.address = address;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

}

 

2、反射获取构造方法并使用

 

3、反射获取成员变量并使用

 

posted @ 2023-12-22 17:18  搬砖滴  阅读(5)  评论(1编辑  收藏  举报