public class Student{
private static int age;
}
Field field = Student.class.getDeclaredField("age");
field.setAccessible(true);
field.get(null); 普通属性获取值 需要传入对象,但是静态属性 不需要传入具体对象,传
null 也可以获取 该字段的值。
public class Student{
private static int age;
}
Field field = Student.class.getDeclaredField("age");
field.setAccessible(true);
field.get(null); 普通属性获取值 需要传入对象,但是静态属性 不需要传入具体对象,传
null 也可以获取 该字段的值。
本文标题:反射--静态成员变量的值获取
本文链接:https://www.haomeiwen.com/subject/xukrtktx.html
网友评论