The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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:以下章节介绍了这些任务:
public
or transient
public
或transient
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
。