I see
MyClass.class.getDeclaredMethods()
MyClass.class.getDeclaredFields()
but how do I get just the non-static or just the static members?
I see
MyClass.class.getDeclaredMethods()
MyClass.class.getDeclaredFields()
but how do I get just the non-static or just the static members?
You can use Modifier#isStatic
for that, for example:
Field[] fields = Main.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())) {
System.out.println(f.getName());
}
}
This will print b
if Main
is:
public class Main {
public String a;
public static String b;
}