主函数:

import java.lang.reflect.Field;

public class reflec {
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
        TestClassEx t = new TestClassEx();
            for (Field f : t.getClass().getDeclaredFields()) {
                if(f.getName().equals("leijun")) {
                    f.setAccessible(true);
                    f.set(t, "indian MI fans");
                    System.out.println(f.getName()+":"+f.get(t));
                }
            }
    }
}

实体类:

class TestClassEx extends TestClass{
    public String leijun = "are you ok?";
}
实体类

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案