code: public static Object getField(Object obj, String name) {
      try {
        Class<? extends Object> klass = obj.getClass();
        do {
          try {
            Field field = klass.getDeclaredField(name);
            field.setAccessible(true);
            return field.get(obj);
          } catch (NoSuchFieldException e) {
            klass = klass.getSuperclass();
          }
        } while (klass != null);
        throw new RuntimeException(); // true no such field exception
      } catch (SecurityException e) {
        throw new RuntimeException(e);
      } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
      } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
docs: Gets a field from an object.
  @param obj object from which to read the field
  @param name the field name to read