Possible Duplicate:
Access to private inherited fields via reflection in Java
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 ??
I have got all class fields (also inherited) and i am using function field.set(Object obj, Object value)
but in this way i can not set inherited class fields :/
I havent got problem to get all class field i am using Spring ReflectionUtils.doWithfield.
i stored all field names in List<String> classField
, so i known all clazz fields also inherited. But my problem is how to set values into all clazz fields.