Get the field modifiers, name and type

int getModifiers()
Returns the Java language modifiers for the field.
String getName()
Returns the name of the field.
Class<?> getType()
Returns a Class object that identifies the declared type.

  import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class Main{
  public static void main(String[] args) {
    Field[] fields = java.lang.Integer.class.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
      Field f = fields[i];
      Class type = f.getType();
      String name = f.getName();
      System.out.print(Modifier.toString(f.getModifiers()));
      System.out.println(" " + type.getCanonicalName() + " " + name + ";");
    }
  }
}
  

The output:


public static final int MIN_VALUE;
public static final int MAX_VALUE;
public static final java.lang.Class TYPE;
static final char[] digits;
static final char[] DigitTens;
static final char[] DigitOnes;
static final int[] sizeTable;
private final int value;
public static final int SIZE;
private static final long serialVersionUID;
Home 
  Java Book 
    Reflection  

Field:
  1. Field Reflection
  2. Get the field modifiers, name and type
  3. Get field value with Reflection
  4. Set field value with Reflection