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.25, 08/23/95
-
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 a boolean indicating whether or not this Class is an
interface.
-
newInstance()
-
Creates a new instance of this Class.
-
toString()
-
Returns the name of this Class or this interface.
forName
public static Class forName(String className) throws ClassNotFoundException
-
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
-
Throws: ClassNotFoundException
-
If the Class could not be found.
newInstance
public Object newInstance() throws InstantiationException, IllegalAccessException
-
Creates a new instance of this Class.
-
Returns:
-
the new instance of this Class.
-
Throws: InstantiationException
-
If you try to instantiate
an abstract class or an interface, or if
the instantiation fails for some other reason.
-
Throws: IllegalAccessException
-
If the class or initializer
is not accessible.
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. An array
of length 0 is returned if this Class implements no interfaces.
getClassLoader
public ClassLoader getClassLoader()
-
Returns the Class loader of this Class. Returns null
if this Class does not have a Class loader.
-
See Also:
-
ClassLoader
isInterface
public boolean isInterface()
-
Returns a boolean indicating whether or not 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 prepended if it is an interface.
-
Overrides:
-
toString in class Object
All Packages This Package Previous Next