Java reflection field value in extends class
- by Lukasz Wozniczka
Hello i hava got problem with init value with java reflection.
i have got simple class
public class A extends B {
private String name;
}
public class B {
private String superName;
}
and also i have got simple function:
public void createRandom(Class<T> clazz , List<String> classFields){
try {
T object = clazz.newInstance();
for(String s : classFields){
clazz.getDeclaredField(s);
}
} catch(Exception e){
}
}
My function do other stuff but i have got problem because i have got error :
java.lang.NoSuchFieldException: superName
How can i set all class field also field from super Class using reflection ??