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发行说明。
From the Java virtual machine's perspective, arrays and enumerated types (or enums) are just classes. 从Java虚拟机的角度来看,数组和枚举类型(或枚举)只是类。Many of the methods in Class
may be used on them. Class
中的许多方法都可以用于它们。Reflection provides a few specific APIs for arrays and enums. 反射为数组和枚举提供了一些特定的API。This lesson uses a series of code samples to describe how to distinguish each of these objects from other classes and operate on them. 本课程使用一系列代码示例来描述如何将这些对象与其他类区分开来,并对它们进行操作。Various errors are also be examined.还将检查各种错误。
Arrays have a component type and a length (which is not part of the type). 数组有一个组件类型和一个长度(它不是该类型的一部分)。Arrays may be manipulated either in their entirety or component by component. 数组可以整体操作,也可以逐个组件操作。Reflection provides the 反射提供java.lang.reflect.Array
class for the latter purpose.java.lang.reflect.Array
类用于后一个目的。
Enums are treated very much like ordinary classes in reflection code. 枚举与反射代码中的普通类非常相似。Class.isEnum()
tells whether a Class
represents and enum
. Class.isEnum()
告诉Class
是否表示和enum
。Class.getEnumConstants()
retrieves the enum constants defined in an enum. 检索枚举中定义的枚举常量。java.lang.reflect.Field.isEnumConstant()
indicates whether a field is an enumerated type.指示字段是否为枚举类型。