Documentation

The Java™ Tutorials
Hide TOC
Arrays and Enumerated Types数组和枚举类型
Trail: The Reflection API

Lesson: Arrays and Enumerated Types课程:数组和枚举类型

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数组

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类用于后一个目的。

Enumerated Types枚举类型

Enums are treated very much like ordinary classes in reflection code. 枚举与反射代码中的普通类非常相似。Class.isEnum() tells whether a Class represents and enum. Class.isEnum()告诉Class是否表示和enumClass.getEnumConstants() retrieves the enum constants defined in an enum. 检索枚举中定义的枚举常量。java.lang.reflect.Field.isEnumConstant() indicates whether a field is an enumerated type.指示字段是否为枚举类型。


Previous page: Previous Lesson
Next page: Arrays