Java Reflection - Java Field.getModifiers()








Syntax

Field.getModifiers() has the following syntax.

public int getModifiers()

Example

In the following code shows how to use Field.getModifiers() method.

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
//from w ww .java  2s  .c  o  m
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 code above generates the following result.