Main Page | Class Hierarchy | Class List | Directories | Class Members | Related Pages

java.lang.Class Class Reference

List of all members.

Detailed Description

This class must be implemented by the vm vendor.

The documented natives must be implemented to support other provided class implementations in this package. An instance of class Class is the in-image representation of a Java class. There are three basic types of Classes

Classes representing object types (classes or interfaces)
These are Classes which represent the class of a simple instance as found in the class hierarchy. The name of one of these Classes is simply the fully qualified class name of the class or interface that it represents. Its signature is the letter "L", followed by its name, followed by a semi-colon (";").
Classes representing base types
These Classes represent the standard Java base types. Although it is not possible to create new instances of these Classes, they are still useful for providing reflection information, and as the component type of array classes. There is one of these Classes for each base type, and their signatures are: The name of a Class representing a base type is the keyword which is used to represent the type in Java source code (i.e. "int" for the int base type.
Classes representing array classes
These are Classes which represent the classes of Java arrays. There is one such Class for all array instances of a given arity (number of dimensions) and leaf component type. In this case, the name of the class is one or more left square brackets (one per dimension in the array) followed by the signature ofP the class representing the leaf component type, which can be either an object type or a base type. The signature of a Class representing an array type is the same as its name.


Public Member Functions

Class[] getClasses ()
 Answers an array containing all public class members of the class which the receiver represents and its superclasses and interfaces.
ClassLoader getClassLoader ()
 Answers the classloader which was used to load the class represented by the receiver.
Class getComponentType ()
 Answers a Class object which represents the receiver's component type if the receiver represents an array type.
Constructor getConstructor (Class parameterTypes[]) throws NoSuchMethodException, SecurityException
 Answers a public Constructor object which represents the constructor described by the arguments.
Constructor[] getConstructors () throws SecurityException
 Answers an array containing Constructor objects describing all constructors which are visible from the current execution context.
Class[] getDeclaredClasses () throws SecurityException
 Answers an array containing all class members of the class which the receiver represents.
Constructor getDeclaredConstructor (Class parameterTypes[]) throws NoSuchMethodException, SecurityException
 Answers a Constructor object which represents the constructor described by the arguments.
Constructor[] getDeclaredConstructors () throws SecurityException
 Answers an array containing Constructor objects describing all constructor which are defined by the receiver.
Field getDeclaredField (String name) throws NoSuchFieldException, SecurityException
 Answers a Field object describing the field in the receiver named by the argument.
Field[] getDeclaredFields () throws SecurityException
 Answers an array containing Field objects describing all fields which are defined by the receiver.
Method getDeclaredMethod (String name, Class parameterTypes[]) throws NoSuchMethodException, SecurityException
 Answers a Method object which represents the method described by the arguments.
Method[] getDeclaredMethods () throws SecurityException
 Answers an array containing Method objects describing all methods which are defined by the receiver.
Class getDeclaringClass ()
 Answers the class which declared the class represented by the receiver.
Field getField (String name) throws NoSuchFieldException, SecurityException
 Answers a Field object describing the field in the receiver named by the argument which must be visible from the current execution context.
Field[] getFields () throws SecurityException
 Answers an array containing Field objects describing all fields which are visible from the current execution context.
Class[] getInterfaces ()
 Answers an array of Class objects which match the interfaces specified in the receiver classes implements declaration.
Method getMethod (String name, Class parameterTypes[]) throws NoSuchMethodException, SecurityException
 Answers a Method object which represents the method described by the arguments.
Method[] getMethods () throws SecurityException
 Answers an array containing Method objects describing all methods which are visible from the current execution context.
int getModifiers ()
 Answers an integer which which is the receiver's modifiers.
String getName ()
 Answers the name of the class which the receiver represents.
ProtectionDomain getProtectionDomain ()
 Answers the ProtectionDomain of the receiver.
URL getResource (String resName)
 Answers a read-only stream on the contents of the resource specified by resName.
InputStream getResourceAsStream (String resName)
 Answers a read-only stream on the contents of the resource specified by resName.
Object[] getSigners ()
 Answers the signers for the class represented by the receiver, or null if there are no signers.
Class getSuperclass ()
 Answers the Class which represents the receiver's superclass.
boolean isArray ()
 Answers true if the receiver represents an array class.
boolean isAssignableFrom (Class cls)
 Answers true if the type represented by the argument can be converted via an identity conversion or a widening reference conversion (i.e.
boolean isInstance (Object object)
 Answers true if the argument is non-null and can be cast to the type of the receiver.
boolean isInterface ()
 Answers true if the receiver represents an interface.
boolean isPrimitive ()
 Answers true if the receiver represents a base type.
Object newInstance () throws IllegalAccessException, InstantiationException
 Answers a new instance of the class represented by the receiver, created by invoking the default (i.e.
String toString ()
 Answers a string containing a concise, human-readable description of the receiver.
Package getPackage ()
 Returns the Package of which this class is a member.
boolean desiredAssertionStatus ()
 Returns the assertion status for this class.

Static Public Member Functions

static Class forName (String className) throws ClassNotFoundException
 Answers a Class object which represents the class named by the argument.
static Class forName (String className, boolean initializeBoolean, ClassLoader classLoader) throws ClassNotFoundException
 Answers a Class object which represents the class named by the argument.

Package Functions

void verify ()
 Verify the specified Class using the VM byte code verifier.
ClassLoader getClassLoaderImpl ()
 This must be provided by the vm vendor, as it is used by other provided class implementations in this package.
ProtectionDomain getPDImpl ()
 Answers the ProtectionDomain of the receiver.

Static Package Functions

static final Class[] getStackClasses (int maxDepth, boolean stopAtPrivileged)
 This must be provided by the vm vendor, as it is used by other provided class implementations in this package.

Static Package Attributes

static final long serialVersionUID = 3206093459760846163L


Member Function Documentation

static Class java.lang.Class.forName String  className  )  throws ClassNotFoundException [static]
 

Answers a Class object which represents the class named by the argument.

The name should be the name of a class as described in the class definition of java.lang.Class, however Classes representing base types can not be found using this method.

Parameters:
className The name of the non-base type class to find
Returns:
the named Class
Exceptions:
ClassNotFoundException If the class could not be found
See also:
java.lang.Class

static Class java.lang.Class.forName String  className,
boolean  initializeBoolean,
ClassLoader  classLoader
throws ClassNotFoundException [static]
 

Answers a Class object which represents the class named by the argument.

The name should be the name of a class as described in the class definition of java.lang.Class, however Classes representing base types can not be found using this method. Security rules will be obeyed.

Parameters:
className The name of the non-base type class to find
initializeBoolean A boolean indicating whether the class should be initialized
classLoader The classloader to use to load the class
Returns:
the named class.
Exceptions:
ClassNotFoundException If the class could not be found
See also:
java.lang.Class

Class [] java.lang.Class.getClasses  ) 
 

Answers an array containing all public class members of the class which the receiver represents and its superclasses and interfaces.

Returns:
the class' public class members
Exceptions:
SecurityException If member access is not allowed
See also:
java.lang.Class

void java.lang.Class.verify  )  [package]
 

Verify the specified Class using the VM byte code verifier.

Exceptions:
VerifyError if the Class cannot be verified

ClassLoader java.lang.Class.getClassLoader  ) 
 

Answers the classloader which was used to load the class represented by the receiver.

Answer null if the class was loaded by the system class loader

Returns:
the receiver's class loader or nil
See also:
java.lang.ClassLoader

ClassLoader java.lang.Class.getClassLoaderImpl  )  [package]
 

This must be provided by the vm vendor, as it is used by other provided class implementations in this package.

Outside of this class, it is used by SecurityManager.checkMemberAccess(), classLoaderDepth(), currentClassLoader() and currentLoadedClass(). Return the ClassLoader for this Class without doing any security checks. The bootstrap ClassLoader is returned, unlike getClassLoader() which returns null in place of the bootstrap ClassLoader.

Returns:
the ClassLoader
See also:
ClassLoader.isSystemClassLoader()

Class java.lang.Class.getComponentType  ) 
 

Answers a Class object which represents the receiver's component type if the receiver represents an array type.

Otherwise answers nil. The component type of an array type is the type of the elements of the array.

Returns:
the component type of the receiver.
See also:
java.lang.Class

Constructor java.lang.Class.getConstructor Class  parameterTypes[]  )  throws NoSuchMethodException, SecurityException
 

Answers a public Constructor object which represents the constructor described by the arguments.

Parameters:
parameterTypes the types of the arguments.
Returns:
the constructor described by the arguments.
Exceptions:
NoSuchMethodException if the constructor could not be found.
SecurityException if member access is not allowed
See also:
getConstructors

Constructor [] java.lang.Class.getConstructors  )  throws SecurityException
 

Answers an array containing Constructor objects describing all constructors which are visible from the current execution context.

Returns:
all visible constructors starting from the receiver.
Exceptions:
SecurityException if member access is not allowed
See also:
getMethods

Class [] java.lang.Class.getDeclaredClasses  )  throws SecurityException
 

Answers an array containing all class members of the class which the receiver represents.

Note that some of the fields which are returned may not be visible in the current execution context.

Returns:
the class' class members
Exceptions:
SecurityException if member access is not allowed
See also:
java.lang.Class

Constructor java.lang.Class.getDeclaredConstructor Class  parameterTypes[]  )  throws NoSuchMethodException, SecurityException
 

Answers a Constructor object which represents the constructor described by the arguments.

Parameters:
parameterTypes the types of the arguments.
Returns:
the constructor described by the arguments.
Exceptions:
NoSuchMethodException if the constructor could not be found.
SecurityException if member access is not allowed
See also:
getConstructors

Constructor [] java.lang.Class.getDeclaredConstructors  )  throws SecurityException
 

Answers an array containing Constructor objects describing all constructor which are defined by the receiver.

Note that some of the fields which are returned may not be visible in the current execution context.

Returns:
the receiver's constructors.
Exceptions:
SecurityException if member access is not allowed
See also:
getMethods

Field java.lang.Class.getDeclaredField String  name  )  throws NoSuchFieldException, SecurityException
 

Answers a Field object describing the field in the receiver named by the argument.

Note that the Constructor may not be visible from the current execution context.

Parameters:
name The name of the field to look for.
Returns:
the field in the receiver named by the argument.
Exceptions:
NoSuchFieldException if the requested field could not be found
SecurityException if member access is not allowed
See also:
getDeclaredFields

Field [] java.lang.Class.getDeclaredFields  )  throws SecurityException
 

Answers an array containing Field objects describing all fields which are defined by the receiver.

Note that some of the fields which are returned may not be visible in the current execution context.

Returns:
the receiver's fields.
Exceptions:
SecurityException If member access is not allowed
See also:
getFields

Method java.lang.Class.getDeclaredMethod String  name,
Class  parameterTypes[]
throws NoSuchMethodException, SecurityException
 

Answers a Method object which represents the method described by the arguments.

Note that the associated method may not be visible from the current execution context.

Parameters:
name the name of the method
parameterTypes the types of the arguments.
Returns:
the method described by the arguments.
Exceptions:
NoSuchMethodException if the method could not be found.
SecurityException If member access is not allowed
See also:
getMethods

Method [] java.lang.Class.getDeclaredMethods  )  throws SecurityException
 

Answers an array containing Method objects describing all methods which are defined by the receiver.

Note that some of the methods which are returned may not be visible in the current execution context.

Exceptions:
SecurityException if member access is not allowed
Returns:
the receiver's methods.
See also:
getMethods

Class java.lang.Class.getDeclaringClass  ) 
 

Answers the class which declared the class represented by the receiver.

This will return null if the receiver is a member of another class.

Returns:
the declaring class of the receiver.

Field java.lang.Class.getField String  name  )  throws NoSuchFieldException, SecurityException
 

Answers a Field object describing the field in the receiver named by the argument which must be visible from the current execution context.

Parameters:
name The name of the field to look for.
Returns:
the field in the receiver named by the argument.
Exceptions:
NoSuchFieldException If the given field does not exist
SecurityException If access is denied
See also:
getDeclaredFields

Field [] java.lang.Class.getFields  )  throws SecurityException
 

Answers an array containing Field objects describing all fields which are visible from the current execution context.

Returns:
all visible fields starting from the receiver.
Exceptions:
SecurityException If member access is not allowed
See also:
getDeclaredFields

Class [] java.lang.Class.getInterfaces  ) 
 

Answers an array of Class objects which match the interfaces specified in the receiver classes implements declaration.

Returns:
Class[] the interfaces the receiver claims to implement.

Method java.lang.Class.getMethod String  name,
Class  parameterTypes[]
throws NoSuchMethodException, SecurityException
 

Answers a Method object which represents the method described by the arguments.

Parameters:
name String the name of the method
parameterTypes Class[] the types of the arguments.
Returns:
Method the method described by the arguments.
Exceptions:
NoSuchMethodException if the method could not be found.
SecurityException if member access is not allowed
See also:
getMethods

Method [] java.lang.Class.getMethods  )  throws SecurityException
 

Answers an array containing Method objects describing all methods which are visible from the current execution context.

Returns:
Method[] all visible methods starting from the receiver.
Exceptions:
SecurityException if member access is not allowed
See also:
getDeclaredMethods

int java.lang.Class.getModifiers  ) 
 

Answers an integer which which is the receiver's modifiers.

Note that the constants which describe the bits which are returned are implemented in class java.lang.reflect.Modifier which may not be available on the target.

Returns:
the receiver's modifiers

String java.lang.Class.getName  ) 
 

Answers the name of the class which the receiver represents.

For a description of the format which is used, see the class definition of java.lang.Class.

Returns:
the receiver's name.
See also:
java.lang.Class

ProtectionDomain java.lang.Class.getProtectionDomain  ) 
 

Answers the ProtectionDomain of the receiver.

Note: In order to conserve space in embedded targets, we allow this method to answer null for classes in the system protection domain (i.e. for system classes). System classes are always given full permissions (i.e. AllPermission). This is not changeable via the java.security.Policy.

Returns:
ProtectionDomain the receiver's ProtectionDomain.
See also:
java.lang.Class

ProtectionDomain java.lang.Class.getPDImpl  )  [package]
 

Answers the ProtectionDomain of the receiver.

This method is for internal use only.

Returns:
ProtectionDomain the receiver's ProtectionDomain.
See also:
java.lang.Class

URL java.lang.Class.getResource String  resName  ) 
 

Answers a read-only stream on the contents of the resource specified by resName.

The mapping between the resource name and the stream is managed by the class' class loader.

Parameters:
resName the name of the resource.
Returns:
a stream on the resource.
See also:
java.lang.ClassLoader

InputStream java.lang.Class.getResourceAsStream String  resName  ) 
 

Answers a read-only stream on the contents of the resource specified by resName.

The mapping between the resource name and the stream is managed by the class' class loader.

Parameters:
resName the name of the resource.
Returns:
a stream on the resource.
See also:
java.lang.ClassLoader

Object [] java.lang.Class.getSigners  ) 
 

Answers the signers for the class represented by the receiver, or null if there are no signers.

Returns:
the signers of the receiver.
See also:
getMethods

Class java.lang.Class.getSuperclass  ) 
 

Answers the Class which represents the receiver's superclass.

For Classes which represent base types, interfaces, and for java.lang.Object the method answers null.

Returns:
the receiver's superclass.

boolean java.lang.Class.isArray  ) 
 

Answers true if the receiver represents an array class.

Returns:
true if the receiver represents an array class false if it does not represent an array class

boolean java.lang.Class.isAssignableFrom Class  cls  ) 
 

Answers true if the type represented by the argument can be converted via an identity conversion or a widening reference conversion (i.e.

if either the receiver or the argument represent primitive types, only the identity conversion applies).

Returns:
true the argument can be assigned into the receiver false the argument cannot be assigned into the receiver
Parameters:
cls Class the class to test
Exceptions:
NullPointerException if the parameter is null

boolean java.lang.Class.isInstance Object  object  ) 
 

Answers true if the argument is non-null and can be cast to the type of the receiver.

This is the runtime version of the instanceof operator.

Returns:
true the argument can be cast to the type of the receiver false the argument is null or cannot be cast to the type of the receiver
Parameters:
object Object the object to test

boolean java.lang.Class.isInterface  ) 
 

Answers true if the receiver represents an interface.

Returns:
true if the receiver represents an interface false if it does not represent an interface

boolean java.lang.Class.isPrimitive  ) 
 

Answers true if the receiver represents a base type.

Returns:
true if the receiver represents a base type false if it does not represent a base type

Object java.lang.Class.newInstance  )  throws IllegalAccessException, InstantiationException
 

Answers a new instance of the class represented by the receiver, created by invoking the default (i.e.

zero-argument) constructor. If there is no such constructor, or if the creation fails (either because of a lack of available memory or because an exception is thrown by the constructor), an InstantiationException is thrown. If the default constructor exists, but is not accessible from the context where this message is sent, an IllegalAccessException is thrown.

Returns:
a new instance of the class represented by the receiver.
Exceptions:
IllegalAccessException if the constructor is not visible to the sender.
InstantiationException if the instance could not be created.

String java.lang.Class.toString  ) 
 

Answers a string containing a concise, human-readable description of the receiver.

Returns:
a printable representation for the receiver.

Package java.lang.Class.getPackage  ) 
 

Returns the Package of which this class is a member.

A class has a Package iff it was loaded from a SecureClassLoader

Returns:
Package the Package of which this class is a member or null

boolean java.lang.Class.desiredAssertionStatus  ) 
 

Returns the assertion status for this class.

Assertion is enabled/disabled based on classloader default, package or class default at runtime

Returns:
the assertion status for this class

static final Class [] java.lang.Class.getStackClasses int  maxDepth,
boolean  stopAtPrivileged
[static, package]
 

This must be provided by the vm vendor, as it is used by other provided class implementations in this package.

This method is used by SecurityManager.classDepth(), and getClassContext() which use the parameters (-1, false) and SecurityManager.classLoaderDepth(), currentClassLoader(), and currentLoadedClass() which use the parameters (-1, true). Walk the stack and answer an array containing the maxDepth most recent classes on the stack of the calling thread. Starting with the caller of the caller of getStackClasses(), return an array of not more than maxDepth Classes representing the classes of running methods on the stack (including native methods). Frames representing the VM implementation of java.lang.reflect are not included in the list. If stopAtPrivileged is true, the walk will terminate at any frame running one of the following methods:

  • java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object;
  • java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;
  • java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
  • java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
If one of the doPrivileged methods is found, the walk terminate and that frame is NOT included in the returned array. Notes:
  • This method operates on the defining classes of methods on stack. NOT the classes of receivers.
  • The item at index zero in the result array describes the caller of the caller of this method.

Parameters:
maxDepth maximum depth to walk the stack, -1 for the entire stack
stopAtPrivileged stop at priviledged classes
Returns:
the array of the most recent classes on the stack


The documentation for this class was generated from the following file:
(c) Copyright 2005 The Apache Software Foundation or its licensors, as applicable.