1 Star 0 Fork 2

ifranxx/JavaDemo

forked from yutf99/JavaDemo 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Test.java 910 Bytes
一键复制 编辑 原始数据 按行查看 历史
yutf99 提交于 2021-02-25 17:35 +08:00 . 换编码
import inner.Person;
import java.lang.reflect.Field;
public class Test {
static class People {
public People(int a){
age = a;
}
public int age;
}
static class Student{
public final String name = "BB";
public final People s = new People(12);
}
public static void main(String[] args) {
Student s = new Student();
System.out.println(s.name);
try{
Class cs = Student.class;
Field fname = cs.getDeclaredField("name");
fname.setAccessible(true);
fname.set(s, "CC");
Field fs = cs.getDeclaredField("s");
fs.setAccessible(true);
fs.set(s, new People(34));
System.out.println(s.name);
System.out.println(s.s.age);
System.out.println(fname.get(s));
}catch (Exception e){
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Infranxx/JavaDemo.git
git@gitee.com:Infranxx/JavaDemo.git
Infranxx
JavaDemo
JavaDemo
master

搜索帮助