Instances of the class Class represent classes and interfaces. An enum is a kind of class and an annotation is a kind of interface. Every array belongs to a class.
Get Class from class name
Name | Summary | |
---|---|---|
static Class<?> | forName(String className) | Returns the Class object associated with the class or interface with the given string name. |
static Class<?> | forName(String name, boolean initialize, ClassLoader loader) | Returns the Class object associated with the class or interface with the given string name, using the given class loader. |
Cast to sub class
Return | Method | Summary |
---|---|---|
<U> Class<? extends U> | asSubclass(Class<U> clazz) | Casts this Class object to represent a subclass of the class represented by the specified class object. |
Cast object to the class or interfacd
Return | Method | Summary |
---|---|---|
T | cast(Object obj) | Casts an object to the class or interface represented by this Class object. |
Get annotations
Return | Method | Summary |
---|---|---|
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. |
<A extends Annotation>A | 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. |
Annotation[] | getDeclaredAnnotations() | Returns all annotations that are directly present on this element. |
Find out the name
Return | Method | Summary |
---|---|---|
String | getCanonicalName() | Returns the canonical name of the underlying class as defined by the Java Language Specification. |
String | getName() | Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. |
String | getSimpleName() | Returns the simple name of the underlying class as given in the source code. |
Get all classes contained
Return | Method | Summary |
---|---|---|
Class<?>[] | getClasses() | Returns an array containing Class objects representing all the public classes and interfaces that are members of the class. |
Class<?>[] | getDeclaredClasses() | Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. |
Get the class loader
Return | Method | Summary |
---|---|---|
ClassLoader | getClassLoader() | Returns the class loader for the class. |
Component type of an array
Return | Method | Summary |
---|---|---|
Class<?> | getComponentType() | Returns the Class representing the component type of an array. |
Get the contructors from a class
Return | Method | Summary |
---|---|---|
Constructor<T> | getConstructor(Class<?>... parameterTypes) | Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. |
Constructor<?>[] | getConstructors() | Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. |
Constructor<T> | getDeclaredConstructor(Class<?>... parameterTypes) | Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object. |
Constructor<?>[] | getDeclaredConstructors() | Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. |
Get fields, methods and classes
Return | Method | Summary |
---|---|---|
Field | getDeclaredField(String name) | Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. |
Field[] | getDeclaredFields() | Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. |
Method | getDeclaredMethod(String name, Class<?>... parameterTypes) | Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. |
Method[] | getDeclaredMethods() | Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. |
Class<?> | getDeclaringClass() | If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared. |
Class<?> | getEnclosingClass() | Returns the immediately enclosing class of the underlying class. |
Method | getMethod(String name, Class<?>... parameterTypes) | Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. |
Method[] | getMethods() | Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces. |
Get method and constructor for a inner or local class
Return | Method | Summary |
---|---|---|
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. |
Get enum constants for a Enum
Return | Method | Summary |
---|---|---|
T[] | getEnumConstants() | Returns the elements of this enum class or null if this Class object does not represent an enum type. |
Get fields
Return | Method | Summary |
---|---|---|
Field | getField(String name) | Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. |
Field[] | getFields() | Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. |
Get interface
Return | Method | Summary |
---|---|---|
Type[] | getGenericInterfaces() | Returns the Types representing the interfaces directly implemented by the class or interface represented by this object. |
Class<?>[] | getInterfaces() | Determines the interfaces implemented by the class or interface represented by this object. |
Get super class
Return | Method | Summary |
---|---|---|
Type | getGenericSuperclass() | Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class. |
Class<? super T> | getSuperclass() | Returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. |
Get the modifiers
Return | Method | Summary |
---|---|---|
int | getModifiers() | Returns the Java language modifiers for this class or interface, encoded in an integer. |
Get the package
Return | Method | Summary |
---|---|---|
Package | getPackage() | Gets the package for this class. |
Get the ProtectionDomain
Return | Method | Summary |
---|---|---|
ProtectionDomain | getProtectionDomain() | Returns the ProtectionDomain of this class. |
Get resources
Return | Method | Summary |
---|---|---|
URL | getResource(String name) | Finds a resource with a given name. |
InputStream | getResourceAsStream(String name) | Finds a resource with a given name. |
Get the signers of this class
Return | Method | Summary |
---|---|---|
Object[] | getSigners() | Gets the signers of this class. |
Get the type parameters
Return | Method | Summary |
---|---|---|
TypeVariable<Class<T>>[] | getTypeParameters() | Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration. |
Check the class type
Return | Method | Summary |
---|---|---|
boolean | isAnnotation() | is it an annotation type. |
boolean | isAnnotationPresent(Class<? extends Annotation> annotationClass) | Is an annotation present. |
boolean | isAnonymousClass() | Is it an anonymous class. |
boolean | isArray() | Is it an array class. |
boolean | isAssignableFrom(Class<?> cls) | Is it assigned from. |
boolean | isEnum() | Is it an enum. |
boolean | isInstance(Object obj) | Is it instance of another object. |
boolean | isInterface() | Is it an interface type. |
boolean | isLocalClass() | Is it a local class. |
boolean | isMemberClass() | Is it a member class. |
boolean | isPrimitive() | Is it a primitive type. |
boolean | isSynthetic() | Is it a synthetic class. |
Create new instance
Return | Method | Summary |
---|---|---|
T | newInstance() | Creates a new instance of the class represented by this Class object. |
Convert class to string
Return | Method | Summary |
---|---|---|
String | toString() | Converts the object to a string. |
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |