Documentation

The Java™ Tutorials
Hide TOC
Fields字段
Trail: The Reflection API
Lesson: 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. java.lang.reflect.Field类中的方法可以检索有关该字段的信息,例如其名称、类型、修饰符和注释。(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(). 类的字段通过调用Class.getFields()来标识。The getFields() method returns an array of Field objects containing one object per accessible public field.getFields()方法返回一个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.字段可以是类(实例)字段,如java.io.Reader.lock;静态字段,如java.lang.Integer.MAX_VALUE;枚举常量,如java.lang.Thread.State.WAITING


Previous page: Members
Next page: Obtaining Field Types