public interface Reflection
| Modifier and Type | Method and Description |
|---|---|
java.lang.Class |
arrayComponentType(java.lang.Class clazz)
Returns the class type of the elements of an array class
|
java.lang.Object |
arrayGet(java.lang.Object array,
int index)
Returns the value of an index in an array
|
int |
arrayLength(java.lang.Object array)
Returns the length of an array
|
void |
arraySet(java.lang.Object array,
int index,
java.lang.Object value)
Sets the value of an index in an array
|
java.lang.Class |
forName(java.lang.String qualifiedName)
Returns the class/interface/annotation/etc.
|
Annotation |
getAnnotation(java.lang.Class clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns the specific annotation
|
Annotation[] |
getAnnotations(java.lang.Class clazz)
Returns declared and generated annotations that this class is annotated with
|
Constructor[] |
getConstructors(java.lang.Class clazz)
Returns an array of all (declared + compiler generated) constructors for a given class
|
Annotation |
getDeclaredAnnotation(java.lang.Class clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns
|
Annotation[] |
getDeclaredAnnotations(java.lang.Class clazz)
Returns declared annotations that this class is annotated with
|
Constructor[] |
getDeclaredConstructors(java.lang.Class clazz)
Returns an array of declared constructors for a given class
|
Field |
getDeclaredField(java.lang.Class clazz,
java.lang.String fieldName)
Returns a declared field with a given name for a given class
|
Field[] |
getDeclaredFields(java.lang.Class clazz)
Returns an array of declared fields for a given class
|
Method[] |
getDeclaredMethods(java.lang.Class clazz)
Returns an array of declared methods for a given class
|
Field |
getField(java.lang.Class clazz,
java.lang.String fieldName)
Returns a declared or compiler generated field with a given name for a given class
|
Field[] |
getFields(java.lang.Class clazz)
Returns an array of all (declared + compiler generated) fields for a given class
|
Method[] |
getMethods(java.lang.Class clazz)
Returns an array of all (declared + compiler generated) methods for a given class
|
boolean |
isAbstract(java.lang.Class clazz)
Returns if the provided class is an abstract class
|
boolean |
isAnnotation(java.lang.Class clazz)
Returns if the provided class is an annotation
|
boolean |
isAnnotationPresent(java.lang.Class clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns if the class is annotated with the provided annotation
|
boolean |
isArray(java.lang.Class clazz)
Returns if the provided class is an array
|
boolean |
isAssignableFrom(java.lang.Class class1,
java.lang.Class class2)
Checks if the class1 is the same class, superclass or superinterface of class2
|
boolean |
isEnum(java.lang.Class clazz)
Returns if the provided class is an enum
|
boolean |
isInstanceOf(java.lang.Class clazz,
java.lang.Object obj)
Checks if the provided object is an instance of the provided class
|
boolean |
isInterface(java.lang.Class clazz)
Returns if the provided class is an interface
|
boolean |
isPrimitive(java.lang.Class clazz)
Returns if the provided class is a primitive
|
java.lang.Object |
newArray(java.lang.Class clazz,
int size)
Creates a new array of elements with the type of the given class
|
java.lang.Object |
newInstance(java.lang.Class clazz)
Creates a new instance of the provided class using the default constructor
|
java.lang.Class forName(java.lang.String qualifiedName)
throws ReflectionException
qualifiedName - The fully qualified name (e.g. java.lang.String)ClassReflectionException - Thrown when the class cannot be foundjava.lang.Object newInstance(java.lang.Class clazz)
throws ReflectionException
clazz - The class to create an instance ofReflectionException - Thrown if the instance could not be createdboolean isInstanceOf(java.lang.Class clazz,
java.lang.Object obj)
clazz - The class to checkobj - The object to checkboolean isAssignableFrom(java.lang.Class class1,
java.lang.Class class2)
class1 - See aboveclass2 - See aboveboolean isAnnotationPresent(java.lang.Class clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
clazz - The class to checkannotationType - The annotation to search forAnnotation[] getAnnotations(java.lang.Class clazz)
clazz - The class to checkAnnotation getAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
clazz - The class to checkannotationType - Annotation[] getDeclaredAnnotations(java.lang.Class clazz)
clazz - The class to checkAnnotation getDeclaredAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
clazz - The class to checkannotationType - Constructor[] getConstructors(java.lang.Class clazz)
clazz - The clazz to get constructors fromConstructor[] getDeclaredConstructors(java.lang.Class clazz)
clazz - The clazz to get constructors fromMethod[] getMethods(java.lang.Class clazz)
clazz - The clazz to get methods fromMethod[] getDeclaredMethods(java.lang.Class clazz)
clazz - The clazz to get methods fromField[] getFields(java.lang.Class clazz)
clazz - The clazz to get fields fromField[] getDeclaredFields(java.lang.Class clazz)
clazz - The clazz to get fields fromField getField(java.lang.Class clazz, java.lang.String fieldName) throws ReflectionException
clazz - The clazz to get the field fromfieldName - The field name to retrieveField instanceReflectionException - Thrown if the field does not existField getDeclaredField(java.lang.Class clazz, java.lang.String fieldName) throws ReflectionException
clazz - The clazz to get the field fromfieldName - The field name to retrieveField instanceReflectionException - Thrown if the field does not existboolean isAbstract(java.lang.Class clazz)
clazz - The class to checkboolean isInterface(java.lang.Class clazz)
clazz - The class to checkboolean isEnum(java.lang.Class clazz)
clazz - The class to checkboolean isPrimitive(java.lang.Class clazz)
clazz - The class to checkboolean isAnnotation(java.lang.Class clazz)
clazz - The class to checkboolean isArray(java.lang.Class clazz)
clazz - The class to checkjava.lang.Class arrayComponentType(java.lang.Class clazz)
clazz - An array classjava.lang.Object arrayGet(java.lang.Object array,
int index)
array - The array instanceindex - The indexvoid arraySet(java.lang.Object array,
int index,
java.lang.Object value)
array - The array instanceindex - The indexvalue - The valueint arrayLength(java.lang.Object array)
array - The array instancejava.lang.Object newArray(java.lang.Class clazz,
int size)
clazz - The array element typesize - The size of the array