java 反射獲得私有屬性的物件
阿新 • • 發佈:2018-12-26
pbulic class Json2Body () {
private ObjectMapper om;
public Json2Body() {
om = new ObjectMapper();
}
pulbic static main() {
try {
Json2Body json2Body = new Json2Body();
Field f = json2Body.getClass().getDeclaredField("om");
f.setAccessible(true);
ObjectMapper om = (ObjectMapper) f.get(json2Body);
} catch (NoSuchFieldException e) {
Assert.fail();
}
}
}