Class java.lang.Class
All Packages This Package Previous Next
Class java.lang.Class
java.lang.Object
|
+----java.lang.Class
-
public final class
Class
-
extends Object
Class objects contain runtime representations of classes. Every
object in the system is an instance of some class, and for each class
there is one of these descriptor objects. A class descriptor is not
modifiable at runtime.
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());
}
-
Version:
-
1.14, 31 Jan 1995
-
forName(String)
-
Returns the runtime class descriptor for the specified class.
-
getClassLoader()
-
Returns the class loader of this class.
-
getInterfaces()
-
Returns the interfaces of this class.
-
getName()
-
Returns the name of this class.
-
getSuperclass()
-
Returns the superclass of this class.
-
isInterface()
-
Returns true if this class is an interface, false otherwise.
-
newInstance()
-
Creates an new instance of this class.
-
toString()
-
Returns the name of this class or this interface.
forName
public static Class forName(String className)
-
Returns the runtime class descriptor for the specified class.
For example the following code fragment returns the runtime
class descriptor for the class named java.lang.Thread:
Class t = Class.forName("java.lang.Thread")
-
Parameters:
-
className
-
the fully qualified name of the desired class
-
Returns:
-
the class
-
Throws: NoClassDefFoundException
-
the class could not be found
newInstance
public Object newInstance()
-
Creates an new instance of this class.
-
Returns:
-
the new instance
-
Throws: IncompatibleTypeException
-
you can't instanciate interfaces
-
Throws: OutOfMemoryException
-
out of memory
getName
public String getName()
-
Returns the name of this class.
getSuperclass
public Class getSuperclass()
-
Returns the superclass of this class.
getInterfaces
public Class getInterfaces()
-
Returns the interfaces of this class.
-
Returns:
-
the interfaces of this class, an array of length
0 is returned if the class implements no interfaces.
getClassLoader
public ClassLoader getClassLoader()
-
Returns the class loader of this class.
-
Returns:
-
the class loader of this class, null is returned
if the class has no class loader.
-
See Also:
-
ClassLoader
isInterface
public boolean isInterface()
-
Returns true if this class is an interface, false otherwise.
-
Returns:
-
a boolean indicating whether this class is an interface
toString
public String toString()
-
Returns the name of this class or this interface. The word
"class" is prepended if it is a class; the word "interface is
is prepended if it is an interface.
-
Returns:
-
a string representing this class or interface
-
Overrides:
-
toString in class Object
All Packages This Package Previous Next