Field: getModifiers() : Field « java.lang.reflect « Java by API






Field: getModifiers()

 


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

public class Main {
  public static void main(String[] args) {
    String name = "java.util.Date";
    try {
      Class cl = Class.forName(name);
      System.out.println("class " + name);
      System.out.println("Its methods:");
      printFields(cl);
      System.out.println();
    } catch (ClassNotFoundException e) {
      System.out.println("Class not found.");
    }
  }

  public static void printFields(Class cl) {
    Field[] fields = cl.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.getName() + " " + name + ";");
    }
  }
}

   
  








Related examples in the same category

1.Field: get(Object obj)
2.Field: getAnnotation(Class annotationClass)
3.Field: getDouble(Object obj)
4.Field: getGenericType()
5.Field: getInt(Object obj)
6.Field: Class getType()
7.Field: isEnumConstant()
8.Field: isSynthetic()
9.Field: setAccessible(boolean flag)
10.Field: setBoolean(Object obj, boolean z)
11.Field: setInt(Object obj, int i)