You can do it like this:
Field[] declaredFields = Test.class.getDeclaredFields();
List<Field> staticFields = new ArrayList<Field>();
for (Field field : declaredFields) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
staticFields.add(field);
}
}
More Related Contents:
- Change private static final field using Java reflection
- How to read the value of a private field from a different class in Java?
- Invoking a static method using reflection
- Getting value of public static final field/property of a class in Java via reflection
- Set field value with reflection
- How can I improve performance of Field.set (perhap using MethodHandles)?
- How do I invoke a Java method when given the method name as a string?
- Why is the Java main method static?
- Why isn’t calling a static method by way of an instance an error for the Java compiler?
- Why are my fields initialized to null or to the default value of zero when I’ve declared and initialized them in my class’ constructor?
- Can a Java class add a method to itself at runtime?
- Are Java static initializers thread safe?
- How to instantiate non static inner class within a static method?
- Can I get information about the local variables using Java reflection?
- Retrieving the inherited attribute names/values using Java Reflection
- Why isn’t a qualified static final variable allowed in a static initialization block?
- Should a “static final Logger” be declared in UPPER-CASE?
- How do I create a static local variable in Java?
- Is there something like instanceOf(Class c) in Java?
- How to get annotations of a member variable?
- Is it possible to override a static method in derived class?
- Java reflection: how to get field value from an object, not knowing its class
- Why we should not use protected static in java
- How and where to use Static modifier in Java?
- Proguard and reflection in Android
- Java reflection – impact of setAccessible(true)
- How do I iterate over class members?
- How to extend a final class in Java
- How to get all imports defined in a class using java reflection?
- Difference between Dynamic and Static type assignments in Java