Get fields in this class
Field getField(String name)
- Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object.
Field[] getFields()
- Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.
import java.lang.reflect.Field;
public class Main {
public static void main(String args[]) {
System.out.println("Fields:");
Field fields[] = new String().getClass().getFields();
for (int i = 0; i < fields.length; i++) {
System.out.println(" " + fields[i]);
}
}
}
The output:
Fields:
public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER