Class

public final class Class extends Object
implements AnnotatedElement GenericDeclaration Serializable Type

Stub implementation of java.lang.Class.

See Also

Public Constructor Summary

Class()

Public Method Summary

<U> Class<? extends U>
asSubclass(Class<U> clazz)
T
cast(Object obj)
boolean
static Class<?>
forName(String name, boolean initialize, ClassLoader loader)
static Class<?>
forName(String className)
<A extends Annotation> A
getAnnotation(Class<A> annotationClass)
Annotation[]
getAnnotations()
Returns annotations that are present on this element.
<T extends Annotation> T[]
getAnnotationsByType(Class<T> annotationClass)
Returns annotations that are associated with this element.
String
ClassLoader
Class[]<?>
Class<?>
Constructor<T>
getConstructor(Class...<?> parameterTypes)
Constructor[]<?>
<T extends Annotation> T
getDeclaredAnnotation(Class<T> annotationClass)
Returns this element's annotation for the specified type if such an annotation is directly present, else null.
Annotation[]
getDeclaredAnnotations()
Returns annotations that are directly present on this element.
<T extends Annotation> T[]
getDeclaredAnnotationsByType(Class<T> annotationClass)
Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present.
Class[]<?>
Constructor<T>
getDeclaredConstructor(Class...<?> parameterTypes)
Constructor[]<?>
Field
Field[]
Method
getDeclaredMethod(String name, Class...<?> parameterTypes)
Method[]
Class<?>
Class<?>
Constructor<?>
Method
T[]
Field
Field[]
Type[]
Type
Class[]<?>
Method
getMethod(String name, Class...<?> parameterTypes)
Method[]
int
String
Package
ProtectionDomain
URL
InputStream
Object[]
String
Class<? super T>
String
TypeVariable[]<Class<T>>
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.
boolean
boolean
isAnnotationPresent(Class<? extends Annotation> annotationType)
Returns true if an annotation for the specified type is present on this element, else false.
boolean
boolean
boolean
boolean
isEnum()
boolean
boolean
boolean
boolean
boolean
boolean
T
String
String
toString()
Returns a string containing a concise, human-readable description of this object.

Inherited Method Summary

Public Constructors

public Class ()

Public Methods

public Class<? extends U> asSubclass (Class<U> clazz)

Parameters
clazz

public T cast (Object obj)

Parameters
obj

public boolean desiredAssertionStatus ()

public static Class<?> forName (String name, boolean initialize, ClassLoader loader)

Parameters
name
initialize
loader

public static Class<?> forName (String className)

Parameters
className

public A getAnnotation (Class<A> annotationClass)

Parameters
annotationClass

public Annotation[] getAnnotations ()

Returns annotations that are present on this element. If there are no annotations present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Returns
  • annotations present on this element

public T[] getAnnotationsByType (Class<T> annotationClass)

Returns annotations that are associated with this element. If there are no annotations associated with this element, the return value is an array of length 0. The difference between this method and getAnnotation(Class) is that this method detects if its argument is a repeatable annotation type (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Parameters
annotationClass the Class object corresponding to the annotation type
Returns
  • all this element's annotations for the specified annotation type if associated with this element, else an array of length zero

public String getCanonicalName ()

public ClassLoader getClassLoader ()

public Class[]<?> getClasses ()

public Class<?> getComponentType ()

public Constructor<T> getConstructor (Class...<?> parameterTypes)

Parameters
parameterTypes

public Constructor[]<?> getConstructors ()

public T getDeclaredAnnotation (Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is directly present, else null. This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.)

Parameters
annotationClass the Class object corresponding to the annotation type
Returns
  • this element's annotation for the specified annotation type if directly present on this element, else null

public Annotation[] getDeclaredAnnotations ()

Returns annotations that are directly present on this element. This method ignores inherited annotations. If there are no annotations directly present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Returns
  • annotations directly present on this element

public T[] getDeclaredAnnotationsByType (Class<T> annotationClass)

Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present. This method ignores inherited annotations. If there are no specified annotations directly or indirectly present on this element, the return value is an array of length 0. The difference between this method and getDeclaredAnnotation(Class) is that this method detects if its argument is a repeatable annotation type (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation if one is present. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Parameters
annotationClass the Class object corresponding to the annotation type
Returns
  • all this element's annotations for the specified annotation type if directly or indirectly present on this element, else an array of length zero

public Class[]<?> getDeclaredClasses ()

public Constructor<T> getDeclaredConstructor (Class...<?> parameterTypes)

Parameters
parameterTypes

public Constructor[]<?> getDeclaredConstructors ()

public Field getDeclaredField (String name)

Parameters
name

public Field[] getDeclaredFields ()

public Method getDeclaredMethod (String name, Class...<?> parameterTypes)

Parameters
name
parameterTypes

public Method[] getDeclaredMethods ()

public Class<?> getDeclaringClass ()

public Class<?> getEnclosingClass ()

public Constructor<?> getEnclosingConstructor ()

public Method getEnclosingMethod ()

public T[] getEnumConstants ()

public Field getField (String name)

Parameters
name

public Field[] getFields ()

public Type[] getGenericInterfaces ()

public Type getGenericSuperclass ()

public Class[]<?> getInterfaces ()

public Method getMethod (String name, Class...<?> parameterTypes)

Parameters
name
parameterTypes

public Method[] getMethods ()

public int getModifiers ()

public String getName ()

public Package getPackage ()

public ProtectionDomain getProtectionDomain ()

public URL getResource (String name)

Parameters
name

public InputStream getResourceAsStream (String name)

Parameters
name

public Object[] getSigners ()

public String getSimpleName ()

public Class<? super T> getSuperclass ()

public String getTypeName ()

public TypeVariable[]<Class<T>> 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

public boolean isAnnotation ()

public boolean isAnnotationPresent (Class<? extends Annotation> annotationType)

Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations.

The truth value returned by this method is equivalent to: getAnnotation(annotationClass) != null

The body of the default method is specified to be the code above.

Parameters
annotationType the Class object corresponding to the annotation type
Returns
  • true if an annotation for the specified annotation type is present on this element, else false

public boolean isAnonymousClass ()

public boolean isArray ()

public boolean isAssignableFrom (Class<?> cls)

Parameters
cls

public boolean isEnum ()

public boolean isInstance (Object obj)

Parameters
obj

public boolean isInterface ()

public boolean isLocalClass ()

public boolean isMemberClass ()

public boolean isPrimitive ()

public boolean isSynthetic ()

public T newInstance ()

public String toGenericString ()

public String toString ()

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 is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.