public class JvmReflection extends java.lang.Object implements Reflection
Reflection
where JVM-based reflection is supportedConstructor 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
Reflection
forName
in interface Reflection
qualifiedName
- The fully qualified name (e.g. java.lang.String)Class
ReflectionException
- Thrown when the class cannot be foundpublic java.lang.Object newInstance(java.lang.Class clazz) throws ReflectionException
Reflection
newInstance
in interface Reflection
clazz
- 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)
Reflection
isInstanceOf
in interface Reflection
clazz
- The class to checkobj
- The object to checkpublic boolean isAssignableFrom(java.lang.Class class1, java.lang.Class class2)
Reflection
isAssignableFrom
in interface Reflection
class1
- See aboveclass2
- See abovepublic boolean isAnnotationPresent(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Reflection
isAnnotationPresent
in interface Reflection
clazz
- The class to checkannotationType
- The annotation to search forpublic Annotation[] getAnnotations(java.lang.Class clazz)
Reflection
getAnnotations
in interface Reflection
clazz
- The class to checkpublic Annotation getAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Reflection
getAnnotation
in interface Reflection
clazz
- The class to checkpublic Annotation[] getDeclaredAnnotations(java.lang.Class clazz)
Reflection
getDeclaredAnnotations
in interface Reflection
clazz
- The class to checkpublic Annotation getDeclaredAnnotation(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Reflection
getDeclaredAnnotation
in interface Reflection
clazz
- The class to checkpublic Constructor[] getConstructors(java.lang.Class clazz)
Reflection
getConstructors
in interface Reflection
clazz
- The clazz to get constructors frompublic Constructor[] getDeclaredConstructors(java.lang.Class clazz)
Reflection
getDeclaredConstructors
in interface Reflection
clazz
- The clazz to get constructors frompublic Method[] getMethods(java.lang.Class clazz)
Reflection
getMethods
in interface Reflection
clazz
- The clazz to get methods frompublic Method[] getDeclaredMethods(java.lang.Class clazz)
Reflection
getDeclaredMethods
in interface Reflection
clazz
- The clazz to get methods frompublic Field[] getFields(java.lang.Class clazz)
Reflection
getFields
in interface Reflection
clazz
- The clazz to get fields frompublic Field[] getDeclaredFields(java.lang.Class clazz)
Reflection
getDeclaredFields
in interface Reflection
clazz
- The clazz to get fields frompublic Field getField(java.lang.Class clazz, java.lang.String fieldName) throws ReflectionException
Reflection
getField
in interface Reflection
clazz
- 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
Reflection
getDeclaredField
in interface Reflection
clazz
- 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)
Reflection
isAbstract
in interface Reflection
clazz
- The class to checkpublic boolean isInterface(java.lang.Class clazz)
Reflection
isInterface
in interface Reflection
clazz
- The class to checkpublic boolean isEnum(java.lang.Class clazz)
Reflection
isEnum
in interface Reflection
clazz
- The class to checkpublic boolean isPrimitive(java.lang.Class clazz)
Reflection
isPrimitive
in interface Reflection
clazz
- The class to checkpublic boolean isAnnotation(java.lang.Class clazz)
Reflection
isAnnotation
in interface Reflection
clazz
- The class to checkpublic boolean isArray(java.lang.Class clazz)
Reflection
isArray
in interface Reflection
clazz
- The class to checkpublic java.lang.Class arrayComponentType(java.lang.Class clazz)
Reflection
arrayComponentType
in interface Reflection
clazz
- An array classpublic java.lang.Object arrayGet(java.lang.Object array, int index)
Reflection
arrayGet
in interface Reflection
array
- The array instanceindex
- The indexpublic void arraySet(java.lang.Object array, int index, java.lang.Object value)
Reflection
arraySet
in interface Reflection
array
- The array instanceindex
- The indexvalue
- The valuepublic int arrayLength(java.lang.Object array)
Reflection
arrayLength
in interface Reflection
array
- The array instancepublic java.lang.Object newArray(java.lang.Class clazz, int size)
Reflection
newArray
in interface Reflection
clazz
- The array element typesize
- The size of the array