Examining Objects at Runtime

The Reflection classes, for the most part, represent parts of a class. The main classes, found in the java.lang.reflect package, are Field, Method, Constructor, Modifier, and Array. There are also some other support classes that you will learn about shortly. You access the Reflection classes through a Class object, which you can get by calling either Class.forName or getClass on an object.

Listing 39.1 defines a simple Person class that can be used to demonstrate Reflection.

Code Listing 39.1. Source Code for Person.java
 package usingj2ee.reflect; public class Person implements java.io.Serializable { public String firstName; public String middleName; public String lastName; public Person() { } public Person(String ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.