1. 程式人生 > >java 反射獲得私有屬性的物件

java 反射獲得私有屬性的物件

       
       
        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();
          }
         
         }
        }