A browser with JavaScript enabled is required for this page to operate properly.
Trail: The Reflection API
Lesson: Members
Fields
Home Page > The Reflection API > Members

Fields

A field is a class, interface, or enum with an associated value. Methods in the java.lang.reflect.Field class can retrieve information about the field, such as its name, type, modifiers, and annotations. (The section Examining Class Modifiers and Types in the Classes lesson describes how to retrieve annotations.) There are also methods which enable dynamic access and modification of the value of the field. These tasks are covered in the following sections:

When writing an application such as a class browser, it might be useful to find out which fields belong to a particular class. A class's fields are identified by invoking Class.getFields(). The getFields() method returns an array of Field objects containing one object per accessible public field.

A public field is accessible if it is a member of either:

A field may be a class (instance) field, such as java.io.Reader.lock , a static field, such as java.lang.Integer.MAX_VALUE , or an enum constant, such as java.lang.Thread.State.WAITING.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Members
Next page: Obtaining Field Types