Package java.lang Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Class

Methods

public  final  class  java.lang.Class
    extends  java.lang.Object  
{
        // Methods
    public static Class forName(String  className);	
    public ClassLoader getClassLoader();	
    public Class[] getInterfaces();	
    public String getName();	
    public Class getSuperclass();	
    public boolean isInterface();	
    public Object newInstance();	
    public String toString();	
}

Instances of the class Class represent classes and interfaces in a running Java application.

There is no public constructor for the class Class. Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and or by calls to the defineClass method in the class loader.


Methods


forName

public static Class forName(String  className) 
throws ClassNotFoundException 

Returns the Class object associated with the class with the given string name.

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")

Return Value:

Returns the Class descriptor for the class with the specified name

ParameterDescription
className the fully qualified name of the desired class

Throw:

ClassNotFoundException

If the class could not be found.


getClassLoader

public ClassLoader getClassLoader() 

Determines the class loader for the class.

Return Value:

Returns The class loader that created the class or interface represented by this object, or null if the class was not created by a class loader.


getInterfaces

public Class[] getInterfaces() 

Determines the interfaces implemented by the class or interface represented by this object..

If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object.

If this object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object.

If the class or interface implements no interfaces, the method returns an array of length 0.

Return Value:

Returns an array of interfaces implemented by this class.


getName

public String getName() 

Return Value:

Returns the fully qualified name of the class or interface represented by this object..


getSuperclass

public Class getSuperclass() 

If this object represents any class other than the class Object, then the object that represents the superclass of that class is returned.

If this object is the one that represents the class Object or this object represents an interface, null is returned.

Return Value:

Returns the superclass of the class represented by this object.


isInterface

public boolean isInterface() 

Return Value:

Returns true if this object represents an interface; false otherwise.


newInstance

public Object newInstance() 
throws InstantiationException, IllegalAccessException 

Creates a new instance of a class.

Return Value:

Returns A newly allocated instance of the class represented by this object. This is done exactly as if by a new expression with an empty argument list.

Throw:

InstantiationException

If an application tries to instantiate an abstract class or an interface, or if the instantiation fails for some other reason.

Throw:

IllegalAccessException

If the class or initializer is not accessible.


toString

public String toString() 

Converts the object to a string. The string representation is the string "class" or "interface" followed by a space and then the fully qualified name of the class.

Return Value:

Returns a string representation of the class object.

Overrides:

toString in class Object .



Top© 1996 Sun Microsystems, Inc. All rights reserved.