Build 1.1_r1 (from source)

java.lang
Class Class<T>

java.lang.Object
  extended by java.lang.Class<T>
All Implemented Interfaces:
Serializable, AnnotatedElement, GenericDeclaration, Type

public final class Class<T>
extends Object
implements Serializable, AnnotatedElement, GenericDeclaration, Type

The in-memory representation of a Java class. This representation serves as the starting point for querying class-related information, a process usually called "reflection". There are basically three types of Class instances: those representing real classes and interfaces, those representing primitive types, and those representing array classes.

Class instances representing object types (classes or interfaces)

These represent an ordinary class or interface as found in the class hierarchy. The name associated with these Class instances is simply the fully qualified class name of the class or interface that it represents. In addition to this human-readable name, each class is also associated by a so-called signature, which is the letter "L", followed by the class name and a semicolon (";"). The signature is what the runtime system uses internally for identifying the class (for example in a DEX file).

Classes representing primitive types

These represent the standard Java primitive types and hence share their names (for example "int" for the int primitive type). Although it is not possible to create new instances based on these Class instances, they are still useful for providing reflection information, and as the component type of array classes. There is one Class instance for each primitive type, and their signatures are:

Classes representing array classes

These represent the classes of Java arrays. There is one such Class instance per combination of array leaf component type and arity (number of dimensions). In this case, the name associated with the Class consists of one or more left square brackets (one per dimension in the array) followed by the signature of the class representing the leaf component type, which can be either an object type or a primitive type. The signature of a Class representing an array type is the same as its name. Examples of array class signatures are:

Since:
Android 1.0
See Also:
Serialized Form

Method Summary
<U> Class<? extends U>
asSubclass(Class<U> clazz)
          Casts this Class to represent a subclass of the specified class.
 T cast(Object obj)
          Casts the specified object to the type represented by this Class.
(package private)  void checkPublicMemberAccess()
          Performs the security checks regarding the access of a public member of this Class.
(package private) static Class<?> classForName(String className, boolean initializeBoolean, ClassLoader classLoader)
           
 boolean desiredAssertionStatus()
          Returns the assertion status for the class represented by this Class.
static Class<?> forName(String className)
          Returns a Class object which represents the class with the specified name.
static Class<?> forName(String className, boolean initializeBoolean, ClassLoader classLoader)
          Returns a Class object which represents the class with the specified name.
<A extends Annotation>
A
getAnnotation(Class<A> annotationClass)
          Returns the annotation of the given type.
 Annotation[] getAnnotations()
          Returns all the annotations of this class.
 String getCanonicalName()
          Returns the canonical name of this class.
(package private)  ClassCache<T> getClassCache()
          Gets the ClassCache for this instance.
 Class[] getClasses()
          Returns an array containing Class objects for all public classes and interfaces that are members of this class.
 ClassLoader getClassLoader()
          Returns the class loader which was used to load the class represented by this Class.
(package private)  ClassLoader getClassLoaderImpl()
          This must be provided by the VM vendor, as it is used by other provided class implementations in this package.
 Class<?> getComponentType()
          Returns a Class object which represents the component type if this class represents an array type.
 Constructor<T> getConstructor(Class... parameterTypes)
          Returns a Constructor object which represents the public constructor matching the specified parameter types.
 Constructor[] getConstructors()
          Returns an array containing Constructor objects for all public constructors for the class represented by this Class.
 Annotation[] getDeclaredAnnotations()
          Returns the annotations that are directly defined on the class represented by this Class.
 Class[] getDeclaredClasses()
          Returns an array containing Class objects for all classes and interfaces that are declared as members of the class which this Class represents.
 Constructor<T> getDeclaredConstructor(Class... parameterTypes)
          Returns a Constructor object which represents the constructor matching the specified parameter types that is declared by the class represented by this Class.
 Constructor[] getDeclaredConstructors()
          Returns an array containing Constructor objects for all constructors declared in the class represented by this Class.
 Field getDeclaredField(String name)
          Returns a Field object for the field with the specified name which is declared in the class represented by this Class.
 Field[] getDeclaredFields()
          Returns an array containing Field objects for all fields declared in the class represented by this Class.
(package private) static Field[] getDeclaredFields(Class<?> clazz, boolean publicOnly)
           
 Method getDeclaredMethod(String name, Class... parameterTypes)
          Returns a Method object which represents the method matching the specified name and parameter types that is declared by the class represented by this Class.
 Method[] getDeclaredMethods()
          Returns an array containing Method objects for all methods declared in the class represented by this Class.
(package private) static Method[] getDeclaredMethods(Class<?> clazz, boolean publicOnly)
          Returns the list of methods without performing any security checks first.
 Class<?> getDeclaringClass()
          Returns the declaring Class of this Class.
 Class<?> getEnclosingClass()
          Returns the enclosing Class of this Class.
 Constructor<?> getEnclosingConstructor()
          Gets the enclosing Constructor of this Class, if it is an anonymous or local/automatic class; otherwise null.
 Method getEnclosingMethod()
          Gets the enclosing Method of this Class, if it is an anonymous or local/automatic class; otherwise null.
 T[] getEnumConstants()
          Gets the enum constants associated with this Class.
 Field getField(String name)
          Returns a Field object which represents the public field with the specified name.
 Field[] getFields()
          Returns an array containing Field objects for all public fields for the class C represented by this Class.
 Type[] getGenericInterfaces()
          Gets the Types of the interfaces that this Class directly implements.
 Type getGenericSuperclass()
          Gets the Type that represents the superclass of this class.
 Class[] getInterfaces()
          Returns an array of Class objects that match the interfaces specified in the implements declaration of the class represented by this Class.
 Method getMethod(String name, Class... parameterTypes)
          Returns a Method object which represents the public method with the specified name and parameter types.
 Method[] getMethods()
          Returns an array containing Method objects for all public methods for the class C represented by this Class.
 int getModifiers()
          Returns an integer that represents the modifiers of the class represented by this Class.
 String getName()
          Returns the name of the class represented by this Class.
 Package getPackage()
          Returns the Package of which the class represented by this Class is a member.
 ProtectionDomain getProtectionDomain()
          Returns the ProtectionDomain of the class represented by this class.
 URL getResource(String resName)
          Returns the URL of the resource specified by resName.
 InputStream getResourceAsStream(String resName)
          Returns a read-only stream for the contents of the resource specified by resName.
 Object[] getSigners()
          Returns the signers for the class represented by this Class or null if either there are no signers or this Class represents a primitive type or void.
 String getSimpleName()
          Returns the simple name of the class represented by this Class as defined in the source code.
(package private) static 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.
 Class<? super T> getSuperclass()
          Returns the Class object which represents the superclass of the class represented by this Class.
 TypeVariable<Class<T>>[] getTypeParameters()
          Returns an array containing TypeVariable objects for type variables declared by the generic class represented by this Class.
 boolean isAnnotation()
          Indicates whether this Class represents an annotation class.
 boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
          Indicates whether the specified annotation is present for the class represented by this Class.
 boolean isAnonymousClass()
          Indicates whether the class represented by this Class is anonymously declared.
 boolean isArray()
          Indicates whether the class represented by this Class is an array class.
 boolean isAssignableFrom(Class<?> cls)
          Indicates whether the specified class type can be converted to the class represented by this Class.
 boolean isEnum()
          Indicates whether the class represented by this Class is an enum.
 boolean isInstance(Object object)
          Indicates whether the specified object can be cast to the class represented by this Class.
 boolean isInterface()
          Indicates whether this Class represents an interface.
 boolean isLocalClass()
          Indicates whether the class represented by this Class is defined locally.
 boolean isMemberClass()
          Indicates whether the class represented by this Class is a member class.
 boolean isPrimitive()
          Indicates whether this Class represents a primitive type.
 boolean isSynthetic()
          Indicates whether this Class represents a synthetic type.
 T newInstance()
          Returns a new instance of the class represented by this Class, created by invoking the default (that is, zero-argument) constructor.
(package private) static void setAccessibleNoCheck(AccessibleObject ao, boolean flag)
          Set the "accessible" flag of the given object, without doing any access checks.
 String toString()
          Returns a string containing a concise, human-readable description of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

forName

public static Class<?> forName(String className)
                        throws ClassNotFoundException
Returns a Class object which represents the class with the specified name. The name should be the name of a class as described in the class definition; however, Classes representing primitive types can not be found using this method.

If the class has not been loaded so far, it is being loaded and linked first. This is done through either the class loader of the calling class or one of its parent class loaders. The class is also being initialized, which means that a possible static initializer block is executed.

Parameters:
className - the name of the non-primitive-type class to find.
Returns:
the named Class instance.
Throws:
ClassNotFoundException - if the requested class can not be found.
LinkageError - if an error occurs during linkage
ExceptionInInitializerError - if an exception occurs during static initialization of a class.
Since:
Android 1.0

forName

public static Class<?> forName(String className,
                               boolean initializeBoolean,
                               ClassLoader classLoader)
                        throws ClassNotFoundException
Returns a Class object which represents the class with the specified name. The name should be the name of a class as described in the class definition, however Classes representing primitive types can not be found using this method. Security rules will be obeyed.

If the class has not been loaded so far, it is being loaded and linked first. This is done through either the specified class loader or one of its parent class loaders. The caller can also request the class to be initialized, which means that a possible static initializer block is executed.

Parameters:
className - the name of the non-primitive-type class to find.
initializeBoolean - indicates whether the class should be initialized.
classLoader - the class loader to use to load the class.
Returns:
the named Class instance.
Throws:
ClassNotFoundException - if the requested class can not be found.
LinkageError - if an error occurs during linkage
ExceptionInInitializerError - if an exception occurs during static initialization of a class.
Since:
Android 1.0

classForName

static Class<?> classForName(String className,
                             boolean initializeBoolean,
                             ClassLoader classLoader)
                      throws ClassNotFoundException
Throws:
ClassNotFoundException

getClasses

public Class[] getClasses()
Returns an array containing Class objects for all public classes and interfaces that are members of this class. This includes public members inherited from super classes and interfaces. If there are no such class members or if this object represents a primitive type then an array of length 0 is returned.

Returns:
the public class members of the class represented by this object.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0

getAnnotation

public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
Returns the annotation of the given type. If there is no such annotation then the method returns null.

Specified by:
getAnnotation in interface AnnotatedElement
Parameters:
annotationClass - the annotation type.
Returns:
the annotation of the given type, or null if there is no such annotation.
Since:
Android 1.0

getAnnotations

public Annotation[] getAnnotations()
Returns all the annotations of this class. If there are no annotations then an empty array is returned.

Specified by:
getAnnotations in interface AnnotatedElement
Returns:
a copy of the array containing this class' annotations.
Since:
Android 1.0
See Also:
getDeclaredAnnotations()

getCanonicalName

public String getCanonicalName()
Returns the canonical name of this class. If this class does not have a canonical name as defined in the Java Language Specification, then the method returns null.

Returns:
this class' canonical name, or null if it does not have a canonical name.
Since:
Android 1.0

getClassLoader

public ClassLoader getClassLoader()
Returns the class loader which was used to load the class represented by this Class. Implementations are free to return null for classes that were loaded by the bootstrap class loader. The Android reference implementation, though, returns a reference to an actual representation of the bootstrap class loader.

Returns:
the class loader for the represented class.
Throws:
SecurityException - if a security manager exists and it does not allow accessing the class loader.
Since:
Android 1.0
See Also:
ClassLoader

getClassLoaderImpl

ClassLoader getClassLoaderImpl()
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()

getComponentType

public Class<?> getComponentType()
Returns a Class object which represents the component type if this class represents an array type. Returns null if this class does not represent an array type. The component type of an array type is the type of the elements of the array.

Returns:
the component type of this class.
Since:
Android 1.0

getConstructor

public Constructor<T> getConstructor(Class... parameterTypes)
                              throws NoSuchMethodException,
                                     SecurityException
Returns a Constructor object which represents the public constructor matching the specified parameter types.

Parameters:
parameterTypes - the parameter types of the requested constructor.
Returns:
the constructor described by parameterTypes.
Throws:
NoSuchMethodException - if the constructor can not be found.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredConstructor(Class...)

getConstructors

public Constructor[] getConstructors()
                              throws SecurityException
Returns an array containing Constructor objects for all public constructors for the class represented by this Class. If there are no public constructors or if this Class represents an array class, a primitive type or void then an empty array is returned.

Returns:
an array with the public constructors of the class represented by this Class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredConstructors()

getDeclaredAnnotations

public Annotation[] getDeclaredAnnotations()
Returns the annotations that are directly defined on the class represented by this Class. Annotations that are inherited are not included in the result. If there are no annotations at all, an empty array is returned.

Specified by:
getDeclaredAnnotations in interface AnnotatedElement
Returns:
a copy of the array containing the annotations defined for the class that this Class represents.
Since:
Android 1.0
See Also:
getAnnotations()

getDeclaredClasses

public Class[] getDeclaredClasses()
                           throws SecurityException
Returns an array containing Class objects for all classes and interfaces that are declared as members of the class which this Class represents. If there are no classes or interfaces declared or if this class represents an array class, a primitive type or void, then an empty array is returned.

Returns:
an array with Class objects for all the classes and interfaces that are used in member declarations.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0

getDeclaredConstructor

public Constructor<T> getDeclaredConstructor(Class... parameterTypes)
                                      throws NoSuchMethodException,
                                             SecurityException
Returns a Constructor object which represents the constructor matching the specified parameter types that is declared by the class represented by this Class.

Parameters:
parameterTypes - the parameter types of the requested constructor.
Returns:
the constructor described by parameterTypes.
Throws:
NoSuchMethodException - if the requested constructor can not be found.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getConstructor(Class...)

getDeclaredConstructors

public Constructor[] getDeclaredConstructors()
                                      throws SecurityException
Returns an array containing Constructor objects for all constructors declared in the class represented by this Class. If there are no constructors or if this Class represents an array class, a primitive type or void then an empty array is returned.

Returns:
an array with the constructors declared in the class represented by this Class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getConstructors()

getDeclaredField

public Field getDeclaredField(String name)
                       throws NoSuchFieldException,
                              SecurityException
Returns a Field object for the field with the specified name which is declared in the class represented by this Class.

Parameters:
name - the name of the requested field.
Returns:
the requested field in the class represented by this class.
Throws:
NoSuchFieldException - if the requested field can not be found.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getField(String)

getDeclaredFields

public Field[] getDeclaredFields()
                          throws SecurityException
Returns an array containing Field objects for all fields declared in the class represented by this Class. If there are no fields or if this Class represents an array class, a primitive type or void then an empty array is returned.

Returns:
an array with the fields declared in the class represented by this class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getFields()

getDeclaredFields

static Field[] getDeclaredFields(Class<?> clazz,
                                 boolean publicOnly)

getDeclaredMethod

public Method getDeclaredMethod(String name,
                                Class... parameterTypes)
                         throws NoSuchMethodException,
                                SecurityException
Returns a Method object which represents the method matching the specified name and parameter types that is declared by the class represented by this Class.

Parameters:
name - the requested method's name.
parameterTypes - the parameter types of the requested method.
Returns:
the method described by name and parameterTypes.
Throws:
NoSuchMethodException - if the requested constructor can not be found.
NullPointerException - if name is null.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getMethod(String, Class...)

getDeclaredMethods

public Method[] getDeclaredMethods()
                            throws SecurityException
Returns an array containing Method objects for all methods declared in the class represented by this Class. If there are no methods or if this Class represents an array class, a primitive type or void then an empty array is returned.

Returns:
an array with the methods declared in the class represented by this Class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getMethods()

getDeclaredMethods

static Method[] getDeclaredMethods(Class<?> clazz,
                                   boolean publicOnly)
Returns the list of methods without performing any security checks first. If no methods exist, an empty array is returned.


getClassCache

ClassCache<T> getClassCache()
Gets the ClassCache for this instance.

Returns:
non-null; the cache object

getDeclaringClass

public Class<?> getDeclaringClass()
Returns the declaring Class of this Class. Returns null if the class is not a member of another class or if this Class represents an array class, a primitive type or void.

Returns:
the declaring Class or null.
Since:
Android 1.0

getEnclosingClass

public Class<?> getEnclosingClass()
Returns the enclosing Class of this Class. If there is no enclosing class the method returns null.

Returns:
the enclosing Class or null.
Since:
Android 1.0

getEnclosingConstructor

public Constructor<?> getEnclosingConstructor()
Gets the enclosing Constructor of this Class, if it is an anonymous or local/automatic class; otherwise null.

Returns:
the enclosing Constructor instance or null.
Since:
Android 1.0

getEnclosingMethod

public Method getEnclosingMethod()
Gets the enclosing Method of this Class, if it is an anonymous or local/automatic class; otherwise null.

Returns:
the enclosing Method instance or null.
Since:
Android 1.0

getEnumConstants

public T[] getEnumConstants()
Gets the enum constants associated with this Class. Returns null if this Class does not represent an enum type.

Returns:
an array with the enum constants or null.
Since:
Android 1.0

getField

public Field getField(String name)
               throws NoSuchFieldException,
                      SecurityException
Returns a Field object which represents the public field with the specified name. This method first searches the class C represented by this Class, then the interfaces implemented by C and finally the superclasses of C.

Parameters:
name - the name of the requested field.
Returns:
the public field specified by name.
Throws:
NoSuchFieldException - if the field can not be found.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredField(String)

getFields

public Field[] getFields()
                  throws SecurityException
Returns an array containing Field objects for all public fields for the class C represented by this Class. Fields may be declared in C, the interfaces it implements or in the superclasses of C. The elements in the returned array are in no particular order.

If there are no public fields or if this class represents an array class, a primitive type or void then an empty array is returned.

Returns:
an array with the public fields of the class represented by this Class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredFields()

getGenericInterfaces

public Type[] getGenericInterfaces()
Gets the Types of the interfaces that this Class directly implements. If the Class represents a primitive type or void then an empty array is returned.

Returns:
an array of Type instances directly implemented by the class represented by this class.
Since:
Android 1.0

getGenericSuperclass

public Type getGenericSuperclass()
Gets the Type that represents the superclass of this class.

Returns:
an instance of Type representing the superclass.
Since:
Android 1.0

getInterfaces

public Class[] getInterfaces()
Returns an array of Class objects that match the interfaces specified in the implements declaration of the class represented by this Class. The order of the elements in the array is identical to the order in the original class declaration. If the class does not implement any interfaces, an empty array is returned.

Returns:
an array with the interfaces of the class represented by this class.
Since:
Android 1.0

getMethod

public Method getMethod(String name,
                        Class... parameterTypes)
                 throws NoSuchMethodException,
                        SecurityException
Returns a Method object which represents the public method with the specified name and parameter types. This method first searches the class C represented by this Class, then the superclasses of C and finally the interfaces implemented by C and finally the superclasses of C for a method with matching name.

Parameters:
name - the requested method's name.
parameterTypes - the parameter types of the requested method.
Returns:
the public field specified by name.
Throws:
NoSuchMethodException - if the method can not be found.
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredMethod(String, Class...)

getMethods

public Method[] getMethods()
                    throws SecurityException
Returns an array containing Method objects for all public methods for the class C represented by this Class. Methods may be declared in C, the interfaces it implements or in the superclasses of C. The elements in the returned array are in no particular order.

If there are no public methods or if this Class represents a primitive type or void then an empty array is returned.

Returns:
an array with the methods of the class represented by this Class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.
Since:
Android 1.0
See Also:
getDeclaredMethods()

checkPublicMemberAccess

void checkPublicMemberAccess()
Performs the security checks regarding the access of a public member of this Class.

Note: Because of the getCallingClassLoader2() check, this method must be called exactly one level deep into a public method on this instance.


getModifiers

public int getModifiers()
Returns an integer that represents the modifiers of the class represented by this Class. The returned value is a combination of bits defined by constants in the Modifier class.

Returns:
the modifiers of the class represented by this Class.
Since:
Android 1.0

getName

public String getName()
Returns the name of the class represented by this Class. For a description of the format which is used, see the class definition of Class.

Returns:
the name of the class represented by this Class.
Since:
Android 1.0

getSimpleName

public String getSimpleName()
Returns the simple name of the class represented by this Class as defined in the source code. If there is no name (that is, the class is anonymous) then an empty string is returned. If the receiver is an array then the name of the underlying type with square braces appended (for example &quot;Integer[]&quot;) is returned.

Returns:
the simple name of the class represented by this Class.
Since:
Android 1.0

getProtectionDomain

public ProtectionDomain getProtectionDomain()
Returns the ProtectionDomain of the class represented by this class.

Note: In order to conserve space in an embedded target like Android, we allow this method to return null for classes in the system protection domain (that is, for system classes). System classes are always given full permissions (that is, AllPermission). This can not be changed through the Policy class.

Returns:
the ProtectionDomain of the class represented by this class.
Throws:
SecurityException - if a security manager exists and it does not allow member access.

getResource

public URL getResource(String resName)
Returns the URL of the resource specified by resName. The mapping between the resource name and the URL is managed by the class' class loader.

Parameters:
resName - the name of the resource.
Returns:
the requested resource's URL object or null if the resource can not be found.
Since:
Android 1.0
See Also:
ClassLoader

getResourceAsStream

public InputStream getResourceAsStream(String resName)
Returns a read-only stream for 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 for the requested resource or null if no resource with the specified name can be found.
Since:
Android 1.0
See Also:
ClassLoader

getSigners

public Object[] getSigners()
Returns the signers for the class represented by this Class or null if either there are no signers or this Class represents a primitive type or void.

Returns:
the signers of the class represented by this Class.
Since:
Android 1.0

getSuperclass

public Class<? super T> getSuperclass()
Returns the Class object which represents the superclass of the class represented by this Class. If this Class represents the Object class, a primitive type, an interface or void then the method returns null. If this Class represents an array class then the Object class is returned.

Returns:
the superclass of the class represented by this Class.
Since:
Android 1.0

getTypeParameters

public TypeVariable<Class<T>>[] getTypeParameters()
Returns an array containing TypeVariable objects for type variables declared by the generic class represented by this Class. Returns an empty array if the class is not generic.

Specified by:
getTypeParameters in interface GenericDeclaration
Returns:
an array with the type variables of the class represented by this class.
Since:
Android 1.0

isAnnotation

public boolean isAnnotation()
Indicates whether this Class represents an annotation class.

Returns:
true if this Class represents an annotation class; false otherwise.
Since:
Android 1.0

isAnnotationPresent

public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
Indicates whether the specified annotation is present for the class represented by this Class.

Specified by:
isAnnotationPresent in interface AnnotatedElement
Parameters:
annotationClass - the annotation to look for.
Returns:
true if the class represented by this Class is annotated with annotationClass; false otherwise.
Since:
Android 1.0

isAnonymousClass

public boolean isAnonymousClass()
Indicates whether the class represented by this Class is anonymously declared.

Returns:
true if the class represented by this Class is anonymous; false otherwise.
Since:
Android 1.0

isArray

public boolean isArray()
Indicates whether the class represented by this Class is an array class.

Returns:
true if the class represented by this Class is an array class; false otherwise.
Since:
Android 1.0

isAssignableFrom

public boolean isAssignableFrom(Class<?> cls)
Indicates whether the specified class type can be converted to the class represented by this Class. Conversion may be done via an identity conversion or a widening reference conversion (if either the receiver or the argument represent primitive types, only the identity conversion applies).

Parameters:
cls - the class to check.
Returns:
true if cls can be converted to the class represented by this Class; false otherwise.
Throws:
NullPointerException - if cls is null.
Since:
Android 1.0

isEnum

public boolean isEnum()
Indicates whether the class represented by this Class is an enum.

Returns:
true if the class represented by this Class is an enum; false otherwise.
Since:
Android 1.0

isInstance

public boolean isInstance(Object object)
Indicates whether the specified object can be cast to the class represented by this Class. This is the runtime version of the instanceof operator.

Parameters:
object - the object to check.
Returns:
true if object can be cast to the type represented by this Class; false if object is null or cannot be cast.
Since:
Android 1.0

isInterface

public boolean isInterface()
Indicates whether this Class represents an interface.

Returns:
true if this Class represents an interface; false otherwise.
Since:
Android 1.0

isLocalClass

public boolean isLocalClass()
Indicates whether the class represented by this Class is defined locally.

Returns:
true if the class represented by this Class is defined locally; false otherwise.
Since:
Android 1.0

isMemberClass

public boolean isMemberClass()
Indicates whether the class represented by this Class is a member class.

Returns:
true if the class represented by this Class is a member class; false otherwise.
Since:
Android 1.0

isPrimitive

public boolean isPrimitive()
Indicates whether this Class represents a primitive type.

Returns:
true if this Class represents a primitive type; false otherwise.
Since:
Android 1.0

isSynthetic

public boolean isSynthetic()
Indicates whether this Class represents a synthetic type.

Returns:
true if this Class represents a synthetic type; false otherwise.
Since:
Android 1.0

newInstance

public T newInstance()
              throws IllegalAccessException,
                     InstantiationException
Returns a new instance of the class represented by this Class, created by invoking the default (that is, 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 method is invoked, an IllegalAccessException is thrown.

Returns:
a new instance of the class represented by this Class.
Throws:
IllegalAccessException - if the default constructor is not visible.
InstantiationException - if the instance can not be created.
SecurityException - if a security manager exists and it does not allow creating new instances.
Since:
Android 1.0

toString

public String toString()
Description copied from class: Object
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's Object.hashCode(), that is, it is equivalent to the following expression:
 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a printable representation of this object.

getPackage

public Package getPackage()
Returns the Package of which the class represented by this Class is a member. Returns null if no Package object was created by the class loader of the class.

Returns:
Package the Package of which this Class is a member or null.
Since:
Android 1.0

desiredAssertionStatus

public boolean desiredAssertionStatus()
Returns the assertion status for the class represented by this Class. Assertion is enabled / disabled based on the class loader, package or class default at runtime.

Returns:
the assertion status for the class represented by this Class.
Since:
Android 1.0

asSubclass

public <U> Class<? extends U> asSubclass(Class<U> clazz)
Casts this Class to represent a subclass of the specified class. If successful, this Class is returned; otherwise a ClassCastException is thrown.

Parameters:
clazz - the required type.
Returns:
this Class cast as a subclass of the given type.
Throws:
ClassCastException - if this Class cannot be cast to the specified type.
Since:
Android 1.0

cast

public T cast(Object obj)
Casts the specified object to the type represented by this Class. If the object is null then the result is also null.

Parameters:
obj - the object to cast.
Returns:
the object that has been cast.
Throws:
ClassCastException - if the object cannot be cast to the specified type.
Since:
Android 1.0

setAccessibleNoCheck

static void setAccessibleNoCheck(AccessibleObject ao,
                                 boolean flag)
Set the "accessible" flag of the given object, without doing any access checks.

Note: This method is implemented in native code, and, as such, is less efficient than using ClassCache.REFLECT to achieve the same goal. This method exists solely to help bootstrap the reflection bridge.

Parameters:
ao - non-null; the object to modify
flag - the new value for the accessible flag

getStackClasses

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. 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:

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

Build 1.1_r1 (from source)

Please submit a feedback, bug or feature