The Java Tutorials have been written for 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.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
From the Java virtual machine's perspective, arrays and enumerated types (or enums) are just classes. Many of the methods in
Class
may be used on them. Reflection provides a few specific APIs for arrays and enums. 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.
Enums are treated very much like ordinary classes in reflection code.
Class.isEnum()
tells whether a
Class
represents and enum
.
Class.getEnumConstants()
retrieves the enum constants defined in an enum.
java.lang.reflect.Field.isEnumConstant()
indicates whether a field is an enumerated type.