|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Class
Note: This class is built into the DVM.
Instances of the class Class
represent classes and interfaces
in a running Java application. Every array also belongs to a class that is
reflected as a Class
object that is shared by all arrays with
the same element type and number of dimensions. The primitive Java types
(boolean
, byte
, char
,
short
, int
, long
,
float
, and double
), and the keyword
void
are also represented as Class
objects.
Class
has no public constructor. Instead Class
objects are constructed automatically by the Java Virtual Machine as classes
are loaded and by calls to the defineClass
method in the class
loader.
The following example uses a Class
object to print the
class name of an object:
void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); }
ClassLoader.defineClass(byte[], int, int)
Method Summary | |
String |
getName()
Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this Class
object, as a String . |
String |
toString()
Converts the object to a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode |
Method Detail |
public String getName()
Class
object, as a String
.
If this Class
object represents a class of arrays, then
the internal form of the name consists of the name of the element type
in Java signature format, preceded by one or more "["
characters representing the depth of array nesting. Thus:
returns "(new Object[3]).getClass().getName()
[Ljava.lang.Object;
" and:
returns "(new int[3][4][5][6][7][8][9]).getClass().getName()
[[[[[[[I
". The encoding of element type names
is as follows:
The class or interface name classname is given in fully qualified form as shown in the example above.B byte C char D double F float I int J long Lclassname; class or interface S short Z boolean
public String toString()
getName
. If this Class
object represents a
primitive type, this method returns the name of the primitive type. If
this Class
object represents void this method returns
"void".
toString
in class Object
|
MIT ACM/IEEE Programming Competition |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |