How to get values of nested class attribute using reflection?
<p>Currently I have classes with several nested classes inside is, like:</p>

<pre><code>public class Foo {

  private Bar bar;

  //getter &amp; setter

  public class Bar {

    private Abc abc;

    //getter &amp; setter

    public class Abc {
      @RequiredParam
      private String property;

      //getter &amp; setter
    }
  }

}
</code></pre>

<p>I am trying to get the value of the fields but I am having a hard time how to achieve this.</p>

<p>So far I have:</p>

<pre><code>  public static boolean isValid(Object paramClazz) throws Exception {
    List&lt;Class&gt; classes = new ArrayList&lt;&gt;();
    getClasses(classes, paramClazz.getClass());

    for (Class clazz : classes) {
      for (Field field : clazz.getDeclaredFields()) {
        if (field.isAnnotationPresent(RequiredParam.class)) {
          field.setAccessible(true);
          //how to get the value? field.get(paramClazz) doesn't work
        }
      }
    }
    return true;
  }

  private static void getClasses(List&lt;Class&gt; classes, Class&lt;?&gt; clazz) {
    if (clazz.getDeclaredClasses().length &gt; 0) {
      for (Class&lt;?&gt; c : clazz.getDeclaredClasses()) {
        getClasses(classes, c);
      }
    }
    classes.add(clazz);
  }
</code></pre>

<p>My goal is to the able to check if the field annotated with @RequiredParam is not null, so I have the method <code>isValid()</code> which will received an object and should be able to check all fields (even the ones inside nested classes) and see if any is missing.</p>

<p>The problem is when I try to call <code>field.get()</code> and I don't know which object I am supposed to pass to this method. Passing the highest level object won't work, because I need somehow to pass only the Abc object to the method.</p>

<p>How can I get the correct object to pass to the <code>field.get()</code> call, considering I can have more or less nested levels in my classes?</p>