here is my example classes, i want get y and z fields by using reflection in this line (Field[] Fields = forName.getDeclaredFields();) am getting empty array. if y and z or not part of class structure then in which part they belong
package test;
import java.lang.reflect.Field;
public class Reflection {
static ClassLoader classLoader = null;
public static void main(String[] args) {
classLoader = Reflection.class.getClassLoader();
Reflection r = new Reflection();
r.getAnnClas();
}
private void getAnnClas() {
Class<?> forName = null;
try {
forName = classLoader.loadClass("test.Wrirter");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Field[] declaredFields = forName.getDeclaredFields();
for (Field field : declaredFields) {
//here i canot find annoumouse calss filed Z
System.out.println(field.getName());
}
}
}
package test;
import java.io.File;
import java.io.FileReader;
public class Wrirter {
public Cb c= new Cb(10, 20) {
public int z = 10;
public int y=120;
@Override
public void doSom() {
super.doSom();
int cbf = getIntC() + getIntB();
}
};
public Wrirter() {
}
}
class Cb {
public int c;
public int b;
public Cb(int c, int b) {
this.c = c;
this.b = b;
}
public void doSom() {
}
public int getIntC() {
return c;
}
public int getIntB() {
return b;
}
public int setIntC() {
return c;
}
public int setIntB() {
return b;
}
}