edu.rice.cs.cunit.subAnnot
Class ClassEx<T>

java.lang.Object
  extended by edu.rice.cs.cunit.subAnnot.AAnnotatedElementEx
      extended by edu.rice.cs.cunit.subAnnot.ClassEx<T>
All Implemented Interfaces:
AnnotatedElementEx

public class ClassEx<T>
extends AAnnotatedElementEx

Extended Class class to support annotations with subclassing.

Author:
Mathias Ricken

Field Summary
 java.lang.Class<T> java
          The java.lang.Class object that represents the class.
 
Fields inherited from class edu.rice.cs.cunit.subAnnot.AAnnotatedElementEx
_ai, _classFileNotFound, _classLoader, _classPath
 
Constructor Summary
ClassEx(java.lang.Class<T> c)
          Create an extended Class instance for the specified class.
ClassEx(java.lang.Class<T> c, java.lang.ClassLoader loader)
          Create an extended Class instance for the specified class.
 
Method Summary
<U> ClassEx<? extends U>
asSubclass(ClassEx<U> clazz)
          Casts this Class object to represent a subclass of the class represented by the specified class object.
 java.lang.Object cast(java.lang.Object obj)
          Casts an object to the class or interface represented by this Class object.
 boolean desiredAssertionStatus()
          Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked.
 boolean equals(java.lang.Object obj)
          Compares this Constructor against the specified object.
static ClassEx<?> forName(java.lang.String s)
          Return an extended Class instance for the class with the specified class name.
static ClassEx<?> forName(java.lang.String s, boolean initialize, java.lang.ClassLoader loader)
          Return an extended Class instance for the class with the specified class name.
protected  java.lang.reflect.AnnotatedElement getAnnotatedElement()
          Return the annotated element.
 java.lang.String getCanonicalName()
          Returns the canonical name of the the underlying class as defined by the Java Language Specification.
 ClassEx[] getClasses()
          Returns a array containing extended Class objects representing all the public classes and interfaces that are members of the class represented by this extended Class object.
 java.lang.ClassLoader getClassLoader()
          Returns the class loader for the class.
 ClassEx<?> getComponentType()
          Returns the extended Class representing the component type of an array.
 ConstructorEx<T> getConstructor(java.lang.Class... parameterTypes)
          Returns an extended Constructor object that reflects the specified public constructor of the class represented by this extended Class object.
 ConstructorEx<T> getConstructor(ClassEx... parameterTypes)
          Returns an extended Constructor object that reflects the specified public constructor of the class represented by this extended Class object.
 ConstructorEx[] getConstructors()
          Returns an array containing extended Constructor objects reflecting all the public constructors of the class represented by this extended Class object.
 ClassEx[] getDeclaredClasses()
          Returns an array of extended Class objects reflecting all the classes and interfaces declared as members of the class represented by this extended Class object.
 ConstructorEx<T> getDeclaredConstructor(java.lang.Class... parameterTypes)
          Returns an extended Constructor object that reflects the specified constructor of the class or interface represented by this extended Class object.
 ConstructorEx<T> getDeclaredConstructor(ClassEx... parameterTypes)
          Returns an extended Constructor object that reflects the specified constructor of the class or interface represented by this extended Class object.
 ConstructorEx[] getDeclaredConstructors()
          Returns an array of extended Constructor objects reflecting all the constructors declared by the class represented by this extended Class object.
 FieldEx getDeclaredField(java.lang.String name)
          Returns an extended Field object that reflects the specified declared field of the class or interface represented by this extended Class object.
 FieldEx[] getDeclaredFields()
          Returns an array of extended Field objects reflecting all the fields declared by the class represented by this extended Class object.
 MethodEx getDeclaredMethod(java.lang.String name, java.lang.Class... parameterTypes)
          Returns an extended Method object that reflects the specified declared method of the class or interface represented by this extended Class object.
 MethodEx getDeclaredMethod(java.lang.String name, ClassEx... parameterTypes)
          Returns an extended Method object that reflects the specified declared method of the class or interface represented by this extended Class object.
 MethodEx[] getDeclaredMethods()
          Returns an array of extended Method objects reflecting all the methods declared by the class represented by this extended Class object.
 ClassEx<?> getDeclaringClass()
          If the class or interface represented by this extended Class object is a member of another class, returns the extended Class object representing the class in which it was declared.
 ClassEx<?> getEnclosingClass()
          Returns the immediately enclosing class of the underlying class.
 ConstructorEx<?> getEnclosingConstructor()
          If this extended Class object represents a local or anonymous class within a constructor, returns an extended Constructor object representing the immediately enclosing constructor of the underlying class.
 MethodEx getEnclosingMethod()
          If this extended Class object represents a local or anonymous class within a method, returns an extended Method object representing the immediately enclosing method of the underlying class.
 java.lang.Object[] getEnumConstants()
          Returns the elements of this enum class or null if this Class object does not represent an enum type.
 FieldEx getField(java.lang.String name)
          Returns an extended Field object that reflects the specified field of the class or interface represented by this extended Class object.
 FieldEx[] getFields()
          Returns an array containing extended Field objects reflecting all the accessible public fields of the class or interface represented by this extended Class object.
 java.lang.reflect.Type[] getGenericInterfaces()
          Returns the Types representing the interfaces directly implemented by the class or interface represented by this object.
 java.lang.reflect.Type getGenericSuperclass()
          Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class.
 ClassEx[] getInterfaces()
          Determines the interfaces implemented by the class or interface represented by this object.
 MethodEx getMethod(java.lang.String name, java.lang.Class... parameterTypes)
          Returns an extended Method object that reflects the specified method of the class or interface represented by this extended Class object.
 MethodEx getMethod(java.lang.String name, ClassEx... parameterTypes)
          Returns an array containing extended Method objects reflecting all the public member methods of the class or interface represented by this extended Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.
 MethodEx[] getMethods()
          Returns an array containing extended Method objects reflecting all the public member methods of the class or interface represented by this extended Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.
 int getModifiers()
          Returns the Java language modifiers for this class or interface, encoded in an integer.
 java.lang.String getName()
          Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.
 PackageEx getPackage()
          Gets the package for this class.
 java.security.ProtectionDomain getProtectionDomain()
          Returns the ProtectionDomain of this class.
 java.net.URL getResource(java.lang.String name)
          Finds a resource with a given name.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Finds a resource with a given name.
 java.lang.Object[] getSigners()
          Gets the signers of this class.
 java.lang.String getSimpleName()
          Returns the simple name of the underlying class as given in the source code.
 ClassEx<? super T> getSuperclass()
          Returns the extended Class representing the superclass of the entity (class, interface, primitive type or void) represented by this extended Class.
 java.lang.reflect.TypeVariable[] getTypeParameters()
          Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order.
 int hashCode()
          Returns a hashcode for this Constructor.
 boolean isAnnotation()
          Returns true if this Class object represents an annotation type.
 boolean isAnonymousClass()
          Returns true if and only if the underlying class is an anonymous class.
 boolean isArray()
          Determines if this Class object represents an array class.
 boolean isAssignableFrom(java.lang.Class cls)
          Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.
 boolean isEnum()
          Returns true if and only if this class was declared as an enum in the source code.
 boolean isInstance(java.lang.Object obj)
          Determines if the specified Object is assignment-compatible with the object represented by this Class.
 boolean isInterface()
          Determines if the specified Class object represents an interface type.
 boolean isLocalClass()
          Returns true if and only if the underlying class is a local class.
 boolean isMemberClass()
          Returns true if and only if the underlying class is a member class.
 boolean isPrimitive()
          Determines if the specified Class object represents a primitive type.
 boolean isSynthetic()
          Returns true if this class is a synthetic class; returns false otherwise.
 T newInstance()
          Creates a new instance of the class represented by this Class object.
 java.lang.String toString()
          Converts the object to a string.
 
Methods inherited from class edu.rice.cs.cunit.subAnnot.AAnnotatedElementEx
findMethodAnnotationsAttributeInfo, getAnnotations, getAnnotations, getAnnotations, getDeclaredAnnotations, getDeclaredAnnotations, getDeclaredAnnotations, getLocalVarAnnotationsAttributeInfo, getParameterAnnotationsAttributeInfo, isAnnotationPresent, isAnnotationPresent, isAvailable, isDeclaredAnnotationPresent, isDeclaredAnnotationPresent, setClassFileNotFound
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

java

public final java.lang.Class<T> java
The java.lang.Class object that represents the class.

Constructor Detail

ClassEx

public ClassEx(java.lang.Class<T> c)
Create an extended Class instance for the specified class.

Parameters:
c - class

ClassEx

public ClassEx(java.lang.Class<T> c,
               java.lang.ClassLoader loader)
Create an extended Class instance for the specified class.

Parameters:
c - class
loader - class loader
Method Detail

forName

public static ClassEx<?> forName(java.lang.String s)
                          throws java.lang.ClassNotFoundException
Return an extended Class instance for the class with the specified class name.

Parameters:
s - class name
Returns:
class
Throws:
java.lang.ClassNotFoundException - if class is not found

forName

public static ClassEx<?> forName(java.lang.String s,
                                 boolean initialize,
                                 java.lang.ClassLoader loader)
                          throws java.lang.ClassNotFoundException
Return an extended Class instance for the class with the specified class name.

Parameters:
s - class name
initialize - whether the class must be initialized
loader - class loader from which the class must be loaded
Returns:
class
Throws:
java.lang.ClassNotFoundException - if class is not found

getAnnotatedElement

protected java.lang.reflect.AnnotatedElement getAnnotatedElement()
Return the annotated element.

Specified by:
getAnnotatedElement in class AAnnotatedElementEx
Returns:
annotated element

getClasses

public ClassEx[] getClasses()
Returns a array containing extended Class objects representing all the public classes and interfaces that are members of the class represented by this extended Class object.

Returns:
array of classes

getComponentType

public ClassEx<?> getComponentType()
Returns the extended Class representing the component type of an array. If this class does not represent an array class this method returns null.

Returns:
component type

getConstructor

public ConstructorEx<T> getConstructor(java.lang.Class... parameterTypes)
                                throws java.lang.NoSuchMethodException,
                                       java.lang.SecurityException
Returns an extended Constructor object that reflects the specified public constructor of the class represented by this extended Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order.

Parameters:
parameterTypes - parameter types
Returns:
extended Constructor object
Throws:
java.lang.NoSuchMethodException - if the constructor is not found
java.lang.SecurityException - if access is denied

getConstructor

public ConstructorEx<T> getConstructor(ClassEx... parameterTypes)
                                throws java.lang.NoSuchMethodException,
                                       java.lang.SecurityException
Returns an extended Constructor object that reflects the specified public constructor of the class represented by this extended Class object. The parameterTypes parameter is an array of extended Class objects that identify the constructor's formal parameter types, in declared order.

Parameters:
parameterTypes - parameter types
Returns:
extended Constructor object
Throws:
java.lang.NoSuchMethodException - if the constructor is not found
java.lang.SecurityException - if access is denied

getConstructors

public ConstructorEx[] getConstructors()
                                throws java.lang.SecurityException
Returns an array containing extended Constructor objects reflecting all the public constructors of the class represented by this extended Class object.

Returns:
array of constructors
Throws:
java.lang.SecurityException - if access is denied

getDeclaredClasses

public ClassEx[] getDeclaredClasses()
Returns an array of extended Class objects reflecting all the classes and interfaces declared as members of the class represented by this extended Class object.

Returns:
array of classes

getDeclaredConstructor

public ConstructorEx<T> getDeclaredConstructor(java.lang.Class... parameterTypes)
                                        throws java.lang.NoSuchMethodException,
                                               java.lang.SecurityException
Returns an extended Constructor object that reflects the specified constructor of the class or interface represented by this extended Class object.

Parameters:
parameterTypes - parameter types
Returns:
extended Constructor object
Throws:
java.lang.NoSuchMethodException - if the constructor is not found
java.lang.SecurityException - if access is denied

getDeclaredConstructor

public ConstructorEx<T> getDeclaredConstructor(ClassEx... parameterTypes)
                                        throws java.lang.NoSuchMethodException,
                                               java.lang.SecurityException
Returns an extended Constructor object that reflects the specified constructor of the class or interface represented by this extended Class object.

Parameters:
parameterTypes - parameter types
Returns:
extended Constructor object
Throws:
java.lang.NoSuchMethodException - if the constructor is not found
java.lang.SecurityException - if access is denied

getDeclaredConstructors

public ConstructorEx[] getDeclaredConstructors()
                                        throws java.lang.SecurityException
Returns an array of extended Constructor objects reflecting all the constructors declared by the class represented by this extended Class object.

Returns:
array of constructors
Throws:
java.lang.SecurityException - if access is denied

getDeclaredField

public FieldEx getDeclaredField(java.lang.String name)
                         throws java.lang.NoSuchFieldException,
                                java.lang.SecurityException
Returns an extended Field object that reflects the specified declared field of the class or interface represented by this extended Class object.

Parameters:
name - field name
Returns:
extended Field object
Throws:
java.lang.NoSuchFieldException - if field not found
java.lang.SecurityException - if access is denied

getDeclaredFields

public FieldEx[] getDeclaredFields()
                            throws java.lang.SecurityException
Returns an array of extended Field objects reflecting all the fields declared by the class represented by this extended Class object.

Returns:
array of fields
Throws:
java.lang.SecurityException - if access is denied

getDeclaredMethod

public MethodEx getDeclaredMethod(java.lang.String name,
                                  java.lang.Class... parameterTypes)
                           throws java.lang.NoSuchMethodException,
                                  java.lang.SecurityException
Returns an extended Method object that reflects the specified declared method of the class or interface represented by this extended Class object.

Parameters:
name - method name
parameterTypes - parameter types
Returns:
extended Method object
Throws:
java.lang.NoSuchMethodException - if method not found
java.lang.SecurityException - if access is denied

getDeclaredMethod

public MethodEx getDeclaredMethod(java.lang.String name,
                                  ClassEx... parameterTypes)
                           throws java.lang.NoSuchMethodException,
                                  java.lang.SecurityException
Returns an extended Method object that reflects the specified declared method of the class or interface represented by this extended Class object.

Parameters:
name - method name
parameterTypes - parameter types
Returns:
extended Method object
Throws:
java.lang.NoSuchMethodException - if method not found
java.lang.SecurityException - if access is denied

getDeclaredMethods

public MethodEx[] getDeclaredMethods()
                              throws java.lang.SecurityException
Returns an array of extended Method objects reflecting all the methods declared by the class represented by this extended Class object.

Returns:
array of methods
Throws:
java.lang.SecurityException - if access is denied

getDeclaringClass

public ClassEx<?> getDeclaringClass()
If the class or interface represented by this extended Class object is a member of another class, returns the extended Class object representing the class in which it was declared. This method returns null if this class or interface is not a member of any other class. If this Class object represents an array class, a primitive type, or void, then this method returns null.

Returns:
the declaring class for this class

getEnclosingClass

public ClassEx<?> getEnclosingClass()
Returns the immediately enclosing class of the underlying class. If the underlying class is a top level class this method returns null.

Returns:
the enclosing class for this class

getEnclosingConstructor

public ConstructorEx<?> getEnclosingConstructor()
If this extended Class object represents a local or anonymous class within a constructor, returns an extended Constructor object representing the immediately enclosing constructor of the underlying class. Returns null otherwise. In particular, this method returns null if the underlying class is a local or anonymous class immediately enclosed by a type declaration, instance initializer or static initializer.

Returns:
the enclosing constructor for this class

getEnclosingMethod

public MethodEx getEnclosingMethod()
If this extended Class object represents a local or anonymous class within a method, returns an extended Method object representing the immediately enclosing method of the underlying class. Returns null otherwise. In particular, this method returns null if the underlying class is a local or anonymous class immediately enclosed by a type declaration, instance initializer or static initializer.

Returns:
the enclosing method for this class

getField

public FieldEx getField(java.lang.String name)
                 throws java.lang.NoSuchFieldException,
                        java.lang.SecurityException
Returns an extended Field object that reflects the specified field of the class or interface represented by this extended Class object.

Parameters:
name - field name
Returns:
extended Field object
Throws:
java.lang.NoSuchFieldException - if field not found
java.lang.SecurityException - if access is denied

getFields

public FieldEx[] getFields()
                    throws java.lang.SecurityException
Returns an array containing extended Field objects reflecting all the accessible public fields of the class or interface represented by this extended Class object.

Returns:
array of fields
Throws:
java.lang.SecurityException - if access is denied

getMethod

public MethodEx getMethod(java.lang.String name,
                          java.lang.Class... parameterTypes)
                   throws java.lang.NoSuchMethodException,
                          java.lang.SecurityException
Returns an extended Method object that reflects the specified method of the class or interface represented by this extended Class object.

Parameters:
name - method name
parameterTypes - parameter types
Returns:
extended Method object
Throws:
java.lang.NoSuchMethodException - if method not found
java.lang.SecurityException - if access is denied

getMethod

public MethodEx getMethod(java.lang.String name,
                          ClassEx... parameterTypes)
                   throws java.lang.NoSuchMethodException,
                          java.lang.SecurityException
Returns an array containing extended Method objects reflecting all the public member methods of the class or interface represented by this extended Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.

Parameters:
name - method name
parameterTypes - parameter types
Returns:
extended Method object
Throws:
java.lang.NoSuchMethodException - if method not found
java.lang.SecurityException - if access is denied

getMethods

public MethodEx[] getMethods()
                      throws java.lang.SecurityException
Returns an array containing extended Method objects reflecting all the public member methods of the class or interface represented by this extended Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.

Returns:
array of methods
Throws:
java.lang.SecurityException - if access is denied

getInterfaces

public ClassEx[] getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.

Returns:
array of interfaces

getPackage

public PackageEx getPackage()
Gets the package for this class.

Returns:
package

getSuperclass

public ClassEx<? super T> getSuperclass()
Returns the extended Class representing the superclass of the entity (class, interface, primitive type or void) represented by this extended Class.

Returns:
superclass

toString

public java.lang.String toString()
Converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName. If this Class object represents a primitive type, this method returns the name of the primitive type. If this Class object represents void this method returns "void".

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this class object.

newInstance

public T newInstance()
              throws java.lang.InstantiationException,
                     java.lang.IllegalAccessException
Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized.

Note that this method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException.

Returns:
a newly allocated instance of the class represented by this object.
Throws:
java.lang.IllegalAccessException - if the class or its nullary constructor is not accessible.
java.lang.InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
java.lang.ExceptionInInitializerError - if the initialization provoked by this method fails.
java.lang.SecurityException - If a security manager, s, is present and any of the following conditions is met:

  • invocation of s.checkMemberAccess(this, Member.PUBLIC) denies creation of new instances of this class

  • the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of s.checkPackageAccess() denies access to the package of this class


isInstance

public boolean isInstance(java.lang.Object obj)
Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.

Specifically, if this Class object represents a declared class, this method returns true if the specified Object argument is an instance of the represented class (or of any of its subclasses); it returns false otherwise. If this Class object represents an array class, this method returns true if the specified Object argument can be converted to an object of the array class by an identity conversion or by a widening reference conversion; it returns false otherwise. If this Class object represents an interface, this method returns true if the class or any superclass of the specified Object argument implements this interface; it returns false otherwise. If this Class object represents a primitive type, this method returns false.

Parameters:
obj - the object to check
Returns:
true if obj is an instance of this class
Since:
JDK1.1

isAssignableFrom

public boolean isAssignableFrom(java.lang.Class cls)
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false.

Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.

Parameters:
cls - the Class object to be checked
Returns:
the boolean value indicating whether objects of the type cls can be assigned to objects of this class
Throws:
java.lang.NullPointerException - if the specified Class parameter is null.
Since:
JDK1.1

isInterface

public boolean isInterface()
Determines if the specified Class object represents an interface type.

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

isArray

public boolean isArray()
Determines if this Class object represents an array class.

Returns:
true if this object represents an array class; false otherwise.
Since:
JDK1.1

isPrimitive

public boolean isPrimitive()
Determines if the specified Class object represents a primitive type.

There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.

These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.

Returns:
true if and only if this class represents a primitive type
Since:
JDK1.1
See Also:
Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE

isAnnotation

public boolean isAnnotation()
Returns true if this Class object represents an annotation type. Note that if this method returns true, isInterface() would also return true, as all annotation types are also interfaces.

Returns:
true if this class object represents an annotation type; false otherwise
Since:
1.5

isSynthetic

public boolean isSynthetic()
Returns true if this class is a synthetic class; returns false otherwise.

Returns:
true if and only if this class is a synthetic class as defined by the Java Language Specification.
Since:
1.5

getName

public java.lang.String getName()
Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.

If this class object represents a reference type that is not an array type then the binary name of the class is returned, as specified by the Java Language Specification, Second Edition.

If this class object represents a primitive type or void, then the name returned is a String equal to the Java language keyword corresponding to the primitive type or void.

If this class object represents a class of arrays, then the internal form of the name consists of the name of the element type preceded by one or more '[' characters representing the depth of the array nesting. The encoding of element type names is as follows:

Element Type Encoding
boolean Z
byte B
char C
class or interface Lclassname;
double D
float F
int I
long J
short S

The class or interface name classname is the binary name of the class specified above.

Examples:

 String.class.getName()
     returns "java.lang.String"
 byte.class.getName()
     returns "byte"
 (new Object[3]).getClass().getName()
     returns "[Ljava.lang.Object;"
 (new int[3][4][5][6][7][8][9]).getClass().getName()
     returns "[[[[[[[I"
 

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

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.

If a security manager is present, and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the class loader for the class whose class loader is requested, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the class loader for the class.

If this object represents a primitive type or void, null is returned.

Overrides:
getClassLoader in class AAnnotatedElementEx
Returns:
the class loader that loaded the class or interface represented by this object.
Throws:
java.lang.SecurityException - if a security manager exists and its checkPermission method denies access to the class loader for the class.
See Also:
ClassLoader, SecurityManager.checkPermission(java.security.Permission), RuntimePermission

getTypeParameters

public java.lang.reflect.TypeVariable[] getTypeParameters()
Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order. Returns an array of length 0 if the underlying generic declaration declares no type variables.

Returns:
an array of TypeVariable objects that represent the type variables declared by this generic declaration
Throws:
java.lang.reflect.GenericSignatureFormatError - if the generic signature of this generic declaration does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
Since:
1.5

getGenericSuperclass

public java.lang.reflect.Type getGenericSuperclass()
Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class.

If the superclass is a parameterized type, the Type object returned must accurately reflect the actual type parameters used in the source code. The parameterized type representing the superclass is created if it had not been created before. See the declaration of ParameterizedType for the semantics of the creation process for parameterized types. If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned. If this object represents an array class then the Class object representing the Object class is returned.

Returns:
the superclass of the class represented by this object
Throws:
java.lang.reflect.GenericSignatureFormatError - if the generic class signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
java.lang.TypeNotPresentException - if the generic superclass refers to a non-existent type declaration
java.lang.reflect.MalformedParameterizedTypeException - if the generic superclass refers to a parameterized type that cannot be instantiated for any reason
Since:
1.5

getGenericInterfaces

public java.lang.reflect.Type[] getGenericInterfaces()
Returns the Types representing the interfaces directly implemented by the class or interface represented by this object.

If a superinterface is a parameterized type, the Type object returned for it must accurately reflect the actual type parameters used in the source code. The parameterized type representing each superinterface is created if it had not been created before. See the declaration of ParameterizedType for the semantics of the creation process for parameterized types.

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. In the case of an array class, the interfaces Cloneable and Serializable are returned in that order.

If this object represents an interface, the array contains objects representing all interfaces directly 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 this object represents a class or interface that implements no interfaces, the method returns an array of length 0.

If this object represents a primitive type or void, the method returns an array of length 0.

Returns:
an array of interfaces implemented by this class
Throws:
java.lang.reflect.GenericSignatureFormatError - if the generic class signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
java.lang.TypeNotPresentException - if any of the generic superinterfaces refers to a non-existent type declaration
java.lang.reflect.MalformedParameterizedTypeException - if any of the generic superinterfaces refer to a parameterized type that cannot be instantiated for any reason
Since:
1.5

getModifiers

public int getModifiers()
Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, static, abstract and interface; they should be decoded using the methods of class Modifier.

If the underlying class is an array class, then its public, private and protected modifiers are the same as those of its component type. If this Class represents a primitive type or void, its public modifier is always true, and its protected and private modifiers are always false. If this object represents an array class, a primitive type or void, then its final modifier is always true and its interface modifier is always false. The values of its other modifiers are not determined by this specification.

The modifier encodings are defined in The Java Virtual Machine Specification, table 4.1.

Returns:
the int representing the modifiers for this class
Since:
JDK1.1
See Also:
Modifier

getSigners

public java.lang.Object[] getSigners()
Gets the signers of this class.

Returns:
the signers of this class, or null if there are no signers. In particular, this method returns null if this object represents a primitive type or void.
Since:
JDK1.1

getSimpleName

public java.lang.String getSimpleName()
Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

The simple name of an array is the simple name of the component type with "[]" appended. In particular the simple name of an array whose component type is anonymous is "[]".

Returns:
the simple name of the underlying class
Since:
1.5

getCanonicalName

public java.lang.String getCanonicalName()
Returns the canonical name of the the underlying class as defined by the Java Language Specification. Returns null if the underlying class does not have a canonical name (i.e., if it is a local or anonymous class or an array whose component type does not have a canonical name).

Returns:
the canonical name of the underlying class if it exists, and null otherwise.
Since:
1.5

isAnonymousClass

public boolean isAnonymousClass()
Returns true if and only if the underlying class is an anonymous class.

Returns:
true if and only if this class is an anonymous class.
Since:
1.5

isLocalClass

public boolean isLocalClass()
Returns true if and only if the underlying class is a local class.

Returns:
true if and only if this class is a local class.
Since:
1.5

isMemberClass

public boolean isMemberClass()
Returns true if and only if the underlying class is a member class.

Returns:
true if and only if this class is a member class.
Since:
1.5

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResourceAsStream(java.lang.String).

Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:

Parameters:
name - name of the desired resource
Returns:
A InputStream object or null if no resource with this name is found
Throws:
java.lang.NullPointerException - If name is null
Since:
JDK1.1

getResource

public java.net.URL getResource(java.lang.String name)
Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResource(java.lang.String).

Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:

Parameters:
name - name of the desired resource
Returns:
A URL object or null if no resource with this name is found
Since:
JDK1.1

getProtectionDomain

public java.security.ProtectionDomain getProtectionDomain()
Returns the ProtectionDomain of this class. If there is a security manager installed, this method first calls the security manager's checkPermission method with a RuntimePermission("getProtectionDomain") permission to ensure it's ok to get the ProtectionDomain.

Returns:
the ProtectionDomain of this class
Throws:
java.lang.SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the ProtectionDomain.
Since:
1.2
See Also:
ProtectionDomain, SecurityManager.checkPermission(java.security.Permission), RuntimePermission

desiredAssertionStatus

public boolean desiredAssertionStatus()
Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked. If this class has had its assertion status set, the most recent setting will be returned; otherwise, if any package default assertion status pertains to this class, the most recent setting for the most specific pertinent package default assertion status is returned; otherwise, if this class is not a system class (i.e., it has a class loader) its class loader's default assertion status is returned; otherwise, the system class default assertion status is returned.

Few programmers will have any need for this method; it is provided for the benefit of the JRE itself. (It allows a class to determine at the time that it is initialized whether assertions should be enabled.) Note that this method is not guaranteed to return the actual assertion status that was (or will be) associated with the specified class when it was (or will be) initialized.

Returns:
the desired assertion status of the specified class.
Since:
1.4
See Also:
ClassLoader.setClassAssertionStatus(java.lang.String, boolean), ClassLoader.setPackageAssertionStatus(java.lang.String, boolean), ClassLoader.setDefaultAssertionStatus(boolean)

isEnum

public boolean isEnum()
Returns true if and only if this class was declared as an enum in the source code.

Returns:
true if and only if this class was declared as an enum in the source code
Since:
1.5

getEnumConstants

public java.lang.Object[] getEnumConstants()
Returns the elements of this enum class or null if this Class object does not represent an enum type.

Returns:
an array containing the values comprising the enum class represented by this Class object in the order they're declared, or null if this Class object does not represent an enum type
Since:
1.5

cast

public java.lang.Object cast(java.lang.Object obj)
Casts an object to the class or interface represented by this Class object.

Parameters:
obj - the object to be cast
Returns:
the object after casting, or null if obj is null
Throws:
java.lang.ClassCastException - if the object is not null and is not assignable to the type T.
Since:
1.5

asSubclass

public <U> ClassEx<? extends U> asSubclass(ClassEx<U> clazz)
Casts this Class object to represent a subclass of the class represented by the specified class object. Checks that that the cast is valid, and throws a ClassCastException if it is not. If this method succeeds, it always returns a reference to this class object.

This method is useful when a client needs to "narrow" the type of a Class object to pass it to an API that restricts the Class objects that it is willing to accept. A cast would generate a compile-time warning, as the correctness of the cast could not be checked at runtime (because generic types are implemented by erasure).

Parameters:
clazz - superclass
Returns:
this Class object, cast to represent a subclass of the specified class object.
Throws:
java.lang.ClassCastException - if this Class object does not represent a subclass of the specified class (here "subclass" includes the class itself).
Since:
1.5

equals

public boolean equals(java.lang.Object obj)
Compares this Constructor against the specified object. Returns true if the objects are the same. Two Constructor objects are the same if they were declared by the same class and have the same formal parameter types.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode for this Constructor. The hashcode is the same as the hashcode for the underlying constructor's declaring class name.

Overrides:
hashCode in class java.lang.Object