Java reflection field value in extends class
Posted
by
Lukasz Wozniczka
on Stack Overflow
See other posts from Stack Overflow
or by Lukasz Wozniczka
Published on 2012-09-18T21:29:45Z
Indexed on
2012/09/18
21:38 UTC
Read the original article
Hit count: 153
java
|reflection
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 ??
© Stack Overflow or respective owner