December 1999
Intermediate to advanced
816 pages
20h 27m
English
The first step to find out anything about a class or interface is to retrieve its Class object. There are three main ways to obtain a Class object:
Use the getClass() method on an instance of an unknown class—for example, Class class = someInstance.getClass();
Use the .class suffix on a known class—for example, Class class = java.awt.TextEvent.class;
Use the Class.forName method with a String that contains the name of the class—for example, Class class = Class.forName(stringNameOfClass);
The best approach to use depends upon whether the class is known at compile time (use the .class suffix), is known only at runtime (use Class.forName()), or is a mystery object reference (getClass()).
Read now
Unlock full access