next up previous contents
Next: java.lang.reflect.Field Up: The API Previous: The API   Contents

java.lang.Class

Instances of class Class represent Java (object and class) types. Instances of this class are created only by the JVM as classes are loaded.

The methods for examining the components of a class come in four variants. I give examples using the set of methods used to access fields. Given a Class object, one can:

Implementation of all these methods is native. Class.forName() causes the JVM to go look for the given class and creates a Class object representing the class. newInstance() causes JVM to try to allocate and initialize (ie. call no-argument constructor) an object of the type corresponding to the class, also doing checks for abstractness/interface/illegal access. getField/getMethod use the internal representation of the Class to create an instance of a Field/Method class.

Field/Method/Class classes have a getDeclaringClass() method which returns the Class object representing the class (or interface) which defines the field/method/constructor/class. In fact, they also all have getName() and getModifiers() methods.

Modifiers are represented as bits in an integer. The Modifier class has constants for the various possibilities.


next up previous contents
Next: java.lang.reflect.Field Up: The API Previous: The API   Contents
Nadeem Hamid 2000-07-24