title: Java reflection field value in extends class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3567372/access-to-private-inherited-fields-via-reflection-in-java">Access to private inherited fields via reflection in Java</a>  </p>
  </blockquote>
  
  
  
  <p>Hello i hava got problem with init value with java reflection. </p>
  
  <p>i have got simple class</p>
  
  <pre><code> public class A extends B {
       private String name;
   }
  
    public class B {
       private String superName;   
    }
  </code></pre>
  
  <p>and also i have got simple function: </p>
  
  <pre><code>   public void createRandom(Class&lt;T&gt; clazz , List&lt;String&gt; classFields){
  
  
      try {
          T object = clazz.newInstance();
          for(String s : classFields){
              clazz.getDeclaredField(s);
          }
  
      } catch(Exception e){
  
      }
  
     }
  </code></pre>
  
  <p>My function do other stuff but i have got problem because i have got error : </p>
  
  <pre><code>java.lang.NoSuchFieldException: superName
  </code></pre>
  
  <p>How can i set all class field also field from super Class  using reflection ??</p>
  
  <p>I have got all class fields (also inherited) and i am using function <code>field.set(Object obj, Object value)</code> but in this way i can not set inherited class fields :/</p>
  
  <p>I havent got problem to get all class field i am using Spring ReflectionUtils.doWithfield. 
  i stored all field names in <code>List&lt;String&gt; classField</code>, so i known all clazz fields also inherited. But my problem is how to set values into all clazz fields.</p>