Get the field modifiers, name and type

ReturnMethodSummary
intgetModifiers()Returns the Java language modifiers for the field.
StringgetName()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;
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.