code: public static void getFields (Class<?> clazz, List<Field> addTo)
      {
          // first get the fields of the superclass
          Class<?> pclazz = clazz.getSuperclass();
          if (pclazz != null && !pclazz.equals(Object.class)) {
              getFields(pclazz, addTo);
          }
  
          // then reflect on this class's declared fields
          Field[] fields;
          try {
              fields = clazz.getDeclaredFields();
          } catch (SecurityException se) {
              System.err.println("Unable to get declared fields of " + clazz.getName() + ": " + se);
              fields = new Field[0];
          }
  
          // override the default accessibility check for the fields
          try {
              AccessibleObject.setAccessible(fields, true);
          } catch (SecurityException se) {
              // ah well, only publics for us
          }
  
          for (Field field : fields) {
              int mods = field.getModifiers();
              if (Modifier.isStatic(mods) || Modifier.isTransient(mods)) {
                  continue; // skip static and transient fields
              }
              addTo.add(field);
          }
      }
docs: Add all the fields of the specifed class (and its ancestors) to the list. Note, if we are
  running in a sandbox, this will only enumerate public members.