public class JvmReflection extends java.lang.Object implements Reflection
Reflection where JVM-based reflection is supported| Constructor and Description |
|---|
JvmReflection() |
| 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
|
public java.lang.Class forName(java.lang.String qualifiedName)
throws ReflectionException
ReflectionforName in interface ReflectionqualifiedName - The fully qualified name (e.g. java.lang.String)ClassReflectionException - Thrown when the class cannot be foundpublic java.lang.Object newInstance(java.lang.Class clazz)
throws ReflectionException
ReflectionnewInstance in interface Reflectionclazz - The class to create an instance ofReflectionException - Thrown if the instance could not be createdpublic boolean isInstanceOf(java.lang.Class clazz,
java.lang.Object obj)
ReflectionisInstanceOf in interface Reflectionclazz - The class to checkobj - The object to checkpublic boolean isAssignableFrom(java.lang.Class class1,
java.lang.Class class2)
ReflectionisAssignableFrom in interface Reflectionclass1 - See aboveclass2 - See abovepublic boolean isAnnotationPresent(java.lang.Class clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
ReflectionisAnnotationPresent in interface Reflectionclazz - The class to checkannotationType - The annotation to search forpublic Annotation[] getAnnotations(java.lang.Class clazz)
ReflectiongetAnnotations in interface Reflectionclazz - The class to checkpublic Annotation getAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
ReflectiongetAnnotation in interface Reflectionclazz - The class to checkpublic Annotation[] getDeclaredAnnotations(java.lang.Class clazz)
ReflectiongetDeclaredAnnotations in interface Reflectionclazz - The class to checkpublic Annotation getDeclaredAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
ReflectiongetDeclaredAnnotation in interface Reflectionclazz - The class to checkpublic Constructor[] getConstructors(java.lang.Class clazz)
ReflectiongetConstructors in interface Reflectionclazz - The clazz to get constructors frompublic Constructor[] getDeclaredConstructors(java.lang.Class clazz)
ReflectiongetDeclaredConstructors in interface Reflectionclazz - The clazz to get constructors frompublic Method[] getMethods(java.lang.Class clazz)
ReflectiongetMethods in interface Reflectionclazz - The clazz to get methods frompublic Method[] getDeclaredMethods(java.lang.Class clazz)
ReflectiongetDeclaredMethods in interface Reflectionclazz - The clazz to get methods frompublic Field[] getFields(java.lang.Class clazz)
ReflectiongetFields in interface Reflectionclazz - The clazz to get fields frompublic Field[] getDeclaredFields(java.lang.Class clazz)
ReflectiongetDeclaredFields in interface Reflectionclazz - The clazz to get fields frompublic Field getField(java.lang.Class clazz, java.lang.String fieldName) throws ReflectionException
ReflectiongetField in interface Reflectionclazz - The clazz to get the field fromfieldName - The field name to retrieveField instanceReflectionException - Thrown if the field does not existpublic Field getDeclaredField(java.lang.Class clazz, java.lang.String fieldName) throws ReflectionException
ReflectiongetDeclaredField in interface Reflectionclazz - The clazz to get the field fromfieldName - The field name to retrieveField instanceReflectionException - Thrown if the field does not existpublic boolean isAbstract(java.lang.Class clazz)
ReflectionisAbstract in interface Reflectionclazz - The class to checkpublic boolean isInterface(java.lang.Class clazz)
ReflectionisInterface in interface Reflectionclazz - The class to checkpublic boolean isEnum(java.lang.Class clazz)
ReflectionisEnum in interface Reflectionclazz - The class to checkpublic boolean isPrimitive(java.lang.Class clazz)
ReflectionisPrimitive in interface Reflectionclazz - The class to checkpublic boolean isAnnotation(java.lang.Class clazz)
ReflectionisAnnotation in interface Reflectionclazz - The class to checkpublic boolean isArray(java.lang.Class clazz)
ReflectionisArray in interface Reflectionclazz - The class to checkpublic java.lang.Class arrayComponentType(java.lang.Class clazz)
ReflectionarrayComponentType in interface Reflectionclazz - An array classpublic java.lang.Object arrayGet(java.lang.Object array,
int index)
ReflectionarrayGet in interface Reflectionarray - The array instanceindex - The indexpublic void arraySet(java.lang.Object array,
int index,
java.lang.Object value)
ReflectionarraySet in interface Reflectionarray - The array instanceindex - The indexvalue - The valuepublic int arrayLength(java.lang.Object array)
ReflectionarrayLength in interface Reflectionarray - The array instancepublic java.lang.Object newArray(java.lang.Class clazz,
int size)
ReflectionnewArray in interface Reflectionclazz - The array element typesize - The size of the array