title: Getting inner class field values using reflection
body: <p>I am trying to access inner class field values using reflection.</p>
  
  <p>Suppose the classes are:-</p>
  
  <pre><code>public class OuterClass  {
      int a;
      public class InnerClass {
          int b;
          InnerClass(int b){
              this.b = b;
         }
      }
  
      public void setInnerField(int val){
          InnerClass a = new InnerClass(val);
      }
  }
  </code></pre>
  
  <p>And the main function has:-</p>
  
  <pre><code>OuterClass obj = new OuterClass();
  obj.a = 10;
  obj.setInnerField(5);
  </code></pre>
  
  <p>Following is what I am trying to get the inner class field value i.e. b
  Referred from <a href="https://stackoverflow.com/questions/32218419/how-i-can-access-inner-class-variable-value-using-reflection-in-java">How i can access inner class variable value using reflection in java?</a></p>
  
  <pre><code>Class[] classes = obj.getClass().getDeclaredClasses();     
  for(Class innerClass: classes){
      //System.out.println(innerClass.getName());
      Field[] fields = innerClass.getDeclaredFields();
      for(Field field : fields){
          //System.out.println(field.getName());
          System.out.println(field.get(obj));  //&lt;-----IllegalArgumentException    
  //Tried with below line too as suggested in above link                                                                     
  System.out.println(field.get(innerClass.getInterfaces())); //&lt;-----IllegalArgumentException
      }           
  }
  </code></pre>
  
  <p>Then what can be  the ways to access the inner class field values at runtime?</p>