Previous | Next | Trail Map | The Reflection API | Contents

Examining Classes

If you are writing a class browser you need a way to get information about classes at run time. For example, you might want to display the names of the class fields, methods, and constructors. Or, you might want to show which interfaces are implemented by a class. To get this information you need to access the Class(in the API reference documentation)object that reflects the class.

For each class, Java Runtime Environment maintains an immutable Class object that contains information about the class. A Class object represents, or reflects, the class. With the Reflection API, you can invoke methods upon a Class object which return Constructor(in the API reference documentation), Method(in the API reference documentation), and Field(in the API reference documentation)objects. By accessing these objects, you can get information about the corresponding constructors, methods, and fields defined in the class.

Retrieving Class Objects

First things first. Before you can find out anything about a class, you must first retrieve its corresponding Class object.

Getting the Class Name

It's easy to find out the name of a Class object. All you have to do is invokde the getName the method.

Discovering Class Modifiers

This section shows you what methods you need to call in order to find out what modifiers a particular class has.

Finding Superclasses

In this section you'll learn how to retrieve all of the Class objects that are the ancestors of a given class.

Identifying the Interfaces Implemented by a Class

If you want to find out what interfaces a class implements, then check out this section.

Examining Interfaces

In this section you'll learn how to tell if a Class object represents an interface or a class. You'll also get some tips on how to get more information about an interface.

Identifying Class Fields

This section shows you how to discover what fields belong to a class, and how to find out more about these fields by accessing Field objects.

Discovering Class Constructors

This section, which introduces the Constructor class, explains how to get information about a class's contructors.

Obtaining Method Information

To find out about a classes methods, you need to retrieve the corresponding Method objects. This section shows you how to do this.


Previous | Next | Trail Map | The Reflection API | Contents