|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Class<T>
public final class Class<T>
Class whose instances represent Java classes.
Constructor Summary | |
---|---|
Class()
|
Method Summary | ||
---|---|---|
|
asSubclass(Class<U> clazz)
asSubclass casts this class to a subclass of this class. |
|
T |
cast(Object obj)
cast casts a given object to this type. |
|
boolean |
desiredAssertionStatus()
If this class would be initialized at this time, its assertion status would be set according to the value returned by this method. |
|
static Class<?> |
forName(String className)
forName loads a class with the given name using the class loader of the calling method's class. |
|
static Class<?> |
forName(String name,
boolean initialize,
ClassLoader loader)
forName loads a class with the given name using the class loader of the calling method's class. |
|
|
getAnnotation(Class<A> annotationClass)
Returns this element's annotation for the specified type if such an annotation is present, else null. |
|
Annotation[] |
getAnnotations()
Returns all annotations present on this element. |
|
String |
getCanonicalName()
Returns the canonical name of the underlying class as defined by the Java Language Specification. |
|
Class<?>[] |
getClasses()
getClasses returns array of classes that are public members of this class or any of this class' superclasses. |
|
ClassLoader |
getClassLoader()
getClassLoader return the class loader that loaded this class into the system. |
|
Class<?> |
getComponentType()
getComponentType returns the element type of an array. |
|
Constructor<T> |
getConstructor(Class<?>... parameterTypes)
getConstructor finds the public constructor with given parameter types in this class. |
|
Constructor<?>[] |
getConstructors()
getConstructors returns an array of all public constructors of this class. |
|
Annotation[] |
getDeclaredAnnotations()
Returns all annotations that are directly present on this element. |
|
Class<?>[] |
getDeclaredClasses()
getDeclaredClasses returns array of classes that are members of this class. |
|
Constructor<T> |
getDeclaredConstructor(Class<?>... parameterTypes)
getDeclaredConstructor searches for a constructor with given parameter types in this clss. |
|
Constructor<T>[] |
getDeclaredConstructors()
getDeclaredConstructors returns an array of all constructors declared in this class. |
|
Field |
getDeclaredField(String name)
getDeclaredField searches for a field with the given name that is declared in this class. |
|
Field[] |
getDeclaredFields()
getDeclaredFields returns an array of all the fields declared in this class. |
|
Method |
getDeclaredMethod(String name,
Class<?>... parameterTypes)
getDeclaredMethod searches for a method with the given name and parameter types in this class. |
|
Method[] |
getDeclaredMethods()
getDeclaredMethods returns an array of all methods declared in this class. |
|
Class<?> |
getDeclaringClass()
getDeclaringClass returns the declaring class for an anonymous inner class. |
|
Class<?> |
getEnclosingClass()
getEnclosingClass returns the enclosing class of an inner class, or null if this is not an inner class. |
|
Constructor<?> |
getEnclosingConstructor()
If this Class object represents a local or anonymous
class within a constructor, returns a Constructor object representing
the immediately enclosing constructor of the underlying
class. |
|
Method |
getEnclosingMethod()
If this Class object represents a local or anonymous
class within a method, returns a Method object representing the
immediately enclosing method of the underlying class. |
|
T[] |
getEnumConstants()
getEnumConstants returns an array with all the constants of this enumeration type, or null if this is not an enumeration type. |
|
Field |
getField(String name)
Looks for a public field accessible through this class. |
|
Field[] |
getFields()
Looks for all public fields in this class and its super classes. |
|
Type[] |
getGenericInterfaces()
Return array of interfaces implemented by this with actual generic parameters |
|
Type |
getGenericSuperclass()
Return super class including actual generic parameters. |
|
Class[] |
getInterfaces()
getInterfaces returns an array of all the interface classes this class implements directly. |
|
Method |
getMethod(String name,
Class<?>... parameterTypes)
getMethod finds the public method with given name and parameter types in this class. |
|
Method[] |
getMethods()
getMethods returns an array of all public methods of this class. |
|
int |
getModifiers()
getModifiers returns modifier set for this class |
|
String |
getName()
getName returns the name of this class. |
|
Package |
getPackage()
Gets the object representing the package which contains this class. |
|
ProtectionDomain |
getProtectionDomain()
getProtectionDomain returns this class' protection domain. |
|
URL |
getResource(String name)
getResource gets a resource from the class loader associated with this class. |
|
InputStream |
getResourceAsStream(String name)
Opens resources as InputStream. |
|
Object[] |
getSigners()
getSigners returns the signers of this class, or null if there are none or this is a primitive type. |
|
String |
getSimpleName()
getSimpleName returns the plain name of this class without generic arguments. |
|
Class<? super T> |
getSuperclass()
getSuperclass gets the super class of this class |
|
TypeVariable<Class<T>>[] |
getTypeParameters()
Return an array of the declared type parameters for a generic class. |
|
boolean |
isAnnotation()
check if this class instance represents an annotation. |
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type is present on this element, else false. |
|
boolean |
isAnonymousClass()
Returns true if and only if the underlying class
is an anonymous class. |
|
boolean |
isArray()
Test if this class is an array. |
|
boolean |
isAssignableFrom(Class<?> cls)
Checks if an object of type cls can be assigned to a variable of this type. |
|
boolean |
isEnum()
isEnum checks if this class is an enumeration class. |
|
boolean |
isInstance(Object obj)
isInstance checks if "obj instanceof >>this<<" would result in true, i.e., if this is a class, obj's class is equal to or a subclass of this, otherwise if this is an interface, obj's class implements the interface, otherwise if this is an array type, obj's type is an array that is assignment compatible to this. |
|
boolean |
isInterface()
Test if this class is an interface. |
|
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()
Test if this class represents a primitive type, i.e., it is one of the values Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, and Void.TYPE. |
|
boolean |
isSynthetic()
check if this class instance represents a synthetic class |
|
T |
newInstance()
newInstance creates a new instance of this class using the constructor with an empty argument list. |
|
String |
toString()
toString creates a string representation of this class |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Class()
Method Detail |
---|
public Class<? super T> getSuperclass()
public String toString()
toString
in class Object
public static Class<?> forName(String className) throws ClassNotFoundException
For JamaicaVM, this method is never called from compiled code, the compiler replaces a call forName(x) by forName(x,true,null) since the class loader of any statically compiled method is the system class loader.
className
- the name of the class to be loaded "." as
package separator.
OutOfMemoryError
- in case of low memory.
StackOverflowError
- in case of stack overflow
ClassFormatError
- in case of loading a broken class
LinkageError
- if class could not be linked
ClassNotFoundException
- if class was not found.
InternalError
- If class could not be found due to an
internal error, e.g. use of too many dynamic types.
ExceptionInInitializerError
- if initialization of the
class caused an exception other than a RuntimeException.public static Class<?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException
name
- the name of the class to be loaded using "." as
package separator.initialize
- true to ask for initialization of the classloader
- the loader to load the class from, null for
system/boot class loader.
OutOfMemoryError
- in case of low memory.
StackOverflowError
- in case of stack overflow
ClassFormatError
- in case of loading a broken class
LinkageError
- if class could not be linked
ClassNotFoundException
- if class was not found.
InternalError
- If class could not be found due to an
internal error, e.g. use of too many dynamic types.
ExceptionInInitializerError
- if initialization of the
class caused an exception other than a RuntimeException.public T newInstance() throws InstantiationException, IllegalAccessException
If a security manager sm is installed, sm.checkMemberAccess(this,Member.PUBLIC) and sm.checkPermission(packageName()) will be called.
If this class does not define a
InstantiationException
- if calling the constructor caused
any of the exceptions InstantiationException,
NoSuchMethodException, IllegalArgumentException or
InvocationTargetException.
IllegalAccessException
- if calling the constructor caused
this exception, i.e., the constructor is not accessible.public boolean isInstance(Object obj)
If this is a primitive type or obj is null, the result is false..
obj
- an object reference or null.
public boolean isAssignableFrom(Class<?> cls)
The result is true iff this is a class and cls is equal to or a subclass of this, otherwise if this is an interface and cls is a class or an interface that is equal to or implements this, otherwise if this is an array type and cls is an array that is assignment compatible to this, else if this is a primitive type and cls is equal to this.
cls
- the source type of the assignment
NullPointerException
- is cls is nullpublic boolean isInterface()
public boolean isArray()
public boolean isPrimitive()
public String getName()
The resulting string is interned().
public ClassLoader getClassLoader()
If a security manager is installed, this does a checkPermission on new RuntimePermission("getClassLoader").
SecurityException
- if checkPermission(new
RuntimePermission("getClassLoader")) failed on the installed
security manager.public Package getPackage()
public Class[] getInterfaces()
public Class<?> getComponentType()
public int getModifiers()
public Object[] getSigners()
public Class<?> getDeclaringClass()
public Class<?>[] getClasses()
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Field[] getFields() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Method[] getMethods() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Constructor<?>[] getConstructors() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Field getField(String name) throws NoSuchFieldException, SecurityException
name
- Name of the field.
NoSuchFieldException
- If no public field with this name was found.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
name
- the name of the method.parameterTypes
- the parameter types of the method.
NoSuchMethodException
- in case the method was not found.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
parameterTypes
- the parameter types of the constructor.
NoSuchMethodException
- in case the constructor was not found.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.PUBLIC) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Class<?>[] getDeclaredClasses() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Field[] getDeclaredFields() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Method[] getDeclaredMethods() throws SecurityException
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Constructor<T>[] getDeclaredConstructors()
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
name
- Name of the field to look for.
NoSuchFieldException
- If there is no field with the given name.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
name
- the name of the methodparameterTypes
- the parameter types of the method.
NoSuchMethodException
- if the method was not found.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
parameterTypes
- the parameter types of the constructor.
SecurityException
- if a security manager sm is installed
and a call to sm.checkMemberAccess(c,Member.DECLARED) or
sm.checkPackageAccess(c.packageName()) for c being this or any
super class of this throws SecurityException.
NoSuchMethodException
public InputStream getResourceAsStream(String name)
name
- Name of the resource.
NullPointerException
- if name is nullgetResource(String)
public URL getResource(String name)
name
- the resource name.
public ProtectionDomain getProtectionDomain()
SecurityException
- if a security manager sm is installed
and a call to sm.checkPermission(new
RuntimePermission("getProtectionDomain")) causes this exception.public boolean desiredAssertionStatus()
public boolean isAnnotation()
public boolean isSynthetic()
public Type getGenericSuperclass()
public Type[] getGenericInterfaces()
public Method getEnclosingMethod()
Class
object represents a local or anonymous
class within a method, returns a 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.
null
.public Constructor<?> getEnclosingConstructor()
Class
object represents a local or anonymous
class within a constructor, returns a 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.
null
.public Class<?> getEnclosingClass()
public String getSimpleName()
public String getCanonicalName()
null
otherwise.public boolean isAnonymousClass()
true
if and only if the underlying class
is an anonymous class.
true
if and only if this class is an anonymous class.public boolean isLocalClass()
true
if and only if the underlying class
is a local class.
true
if and only if this class is a local class.public boolean isMemberClass()
true
if and only if the underlying class
is a member class.
true
if and only if this class is a member class.public boolean isEnum()
public T[] getEnumConstants()
public T cast(Object obj)
obj
- the object to be casted.
ClassCastException
- if !isInstance(obj).public <U> Class<? extends U> asSubclass(Class<U> clazz)
clazz
- a subclass of this
ClassCastException
- if this is not a subclass of clazz.public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
AnnotatedElement
isAnnotationPresent
in interface AnnotatedElement
annotationClass
- the Class object corresponding to the
annotation type
NullPointerException
- if the given annotation class is nullpublic <A extends Annotation> A getAnnotation(Class<A> annotationClass)
AnnotatedElement
getAnnotation
in interface AnnotatedElement
annotationClass
- the Class object corresponding to the
annotation type
NullPointerException
- if the given annotation class is nullpublic Annotation[] getAnnotations()
AnnotatedElement
getAnnotations
in interface AnnotatedElement
public Annotation[] getDeclaredAnnotations()
AnnotatedElement
getDeclaredAnnotations
in interface AnnotatedElement
public TypeVariable<Class<T>>[] getTypeParameters()
getTypeParameters
in interface GenericDeclaration
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |