【发布时间】:2014-07-28 11:50:50
【问题描述】:
我正在处理一个非开源项目,我需要修改它的一个或多个类。
在一个类中是以下集合:
private Map<Integer, TTP> ttp = new HashMap<>();
我需要做的就是在这里使用反射并使用concurrenthashmap。 我试过下面的代码,但它不起作用。
Field f = ..getClass().getDeclaredField("ttp");
f.setAccessible(true);
f.set(null, new ConcurrentHashMap<>());
【问题讨论】:
-
这是什么意思:但它不起作用?你在哪个对象上调用
.getClass().getDeclaredField("ttp")
标签: java reflection field