public class Reflection extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Reflection.ClassHierarchy |
static class |
Reflection.FullHierarchy |
static class |
Reflection.Interfaces
Inclusivity literals for
hierarchy(Class, Interfaces). |
| Constructor and Description |
|---|
Reflection() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
find(Class<?> clazz,
Function<Class<?>,T> search)
Perform a search against the class hierarchy.
|
static Object |
getAnnotationValue(Annotation annotation,
String name)
Get the named value from the specified
Annotation. |
static <T> Constructor<T> |
getDeclaredConstructor(Class<T> clazz,
Class<?>... parameters)
Get the declared constructor from
clazz. |
static <T> Constructor<? extends T>[] |
getDeclaredConstructors(Class<T> clazz)
Convenient point for
Privilizing Class.getDeclaredConstructors(). |
static Field |
getDeclaredField(Class<?> clazz,
String fieldName)
Get the declared field from
clazz. |
static Field[] |
getDeclaredFields(Class<?> clazz)
Convenient point for
Privilizing Class.getDeclaredFields(). |
static Method |
getDeclaredMethod(Class<?> clazz,
String name,
Class<?>... parameters)
Get the declared method from
clazz. |
static Method[] |
getDeclaredMethods(Class<?> clazz)
Convenient point for
Privilizing Class.getDeclaredMethods(). |
static String |
getProperty(String name)
Convenient point for
Privilizing System.getProperty(String). |
static Method |
getPublicMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
|
static Iterable<Class<?>> |
hierarchy(Class<?> type,
Reflection.Interfaces interfacesBehavior)
Get an
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order. |
static ClassLoader |
loaderFromClassOrThread(Class<?> clazz)
|
static ClassLoader |
loaderFromThreadOrClass(Class<?> fallbackClass)
Get a
ClassLoader preferring
Thread.getContextClassLoader() of current Thread over
that of fallbackClass. |
static void |
makeAccessible(AccessibleObject o)
Set the accessibility of
o to true. |
static <T> T |
newInstance(Class<T> cls)
Construct a new instance of
cls using its default constructor. |
static Class<?> |
primitiveToWrapper(Class<?> cls)
Converts the specified primitive Class object to its corresponding
wrapper Class object.
|
static Class<?> |
toClass(String className) |
static Class<?> |
toClass(String className,
boolean resolve,
ClassLoader loader)
Return the class for the given string, correctly handling
primitive types.
|
static Class<?> |
toClass(String className,
ClassLoader loader)
Return the class for the given string, correctly handling
primitive types.
|
static Class<?> |
wrapperToPrimitive(Class<?> cls) |
public static Class<?> primitiveToWrapper(Class<?> cls)
Converts the specified primitive Class object to its corresponding wrapper Class object.
NOTE: From v2.2, this method handles Void.TYPE,
returning Void.TYPE.
cls - the class to convert, may be nullcls or cls if
cls is not a primitive. null if null input.public static Object getAnnotationValue(Annotation annotation, String name) throws IllegalAccessException, InvocationTargetException
Annotation.annotation - name - IllegalAccessExceptionInvocationTargetExceptionpublic static ClassLoader loaderFromClassOrThread(Class<?> clazz)
clazz - ClassLoaderpublic static ClassLoader loaderFromThreadOrClass(Class<?> fallbackClass)
ClassLoader preferring
Thread.getContextClassLoader() of current Thread over
that of fallbackClass.fallbackClass - ClassLoaderpublic static Class<?> toClass(String className) throws ClassNotFoundException
ClassNotFoundExceptionpublic static Class<?> toClass(String className, ClassLoader loader) throws ClassNotFoundException
RuntimeException - on load errorClassNotFoundExceptionpublic static Class<?> toClass(String className, boolean resolve, ClassLoader loader) throws ClassNotFoundException
RuntimeException - on load errorClassNotFoundExceptionpublic static String getProperty(String name)
Privilizing System.getProperty(String).name - public static Field getDeclaredField(Class<?> clazz, String fieldName)
clazz.clazz - fieldName - Field or nullpublic static Field[] getDeclaredFields(Class<?> clazz)
Privilizing Class.getDeclaredFields().clazz - Field arraypublic static <T> Constructor<T> getDeclaredConstructor(Class<T> clazz, Class<?>... parameters)
clazz.clazz - parameters - Constructor or nullpublic static Method getDeclaredMethod(Class<?> clazz, String name, Class<?>... parameters)
clazz.clazz - name - parameters - Method or nullpublic static Method[] getDeclaredMethods(Class<?> clazz)
Privilizing Class.getDeclaredMethods().clazz - Method arraypublic static <T> Constructor<? extends T>[] getDeclaredConstructors(Class<T> clazz)
Privilizing Class.getDeclaredConstructors().clazz - Constructor arraypublic static Method getPublicMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
clazz - methodName - Method or nullpublic static <T> T find(Class<?> clazz, Function<Class<?>,T> search)
clazz - search - nullpublic static <T> T newInstance(Class<T> cls)
cls using its default constructor.cls - public static void makeAccessible(AccessibleObject o)
o to true.o - public static Iterable<Class<?>> hierarchy(Class<?> type, Reflection.Interfaces interfacesBehavior)
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order.
Taken from commons-lang3.type - the type to get the class hierarchy frominterfacesBehavior - switch indicating whether to include or exclude interfacesCopyright © 2010–2020 The Apache Software Foundation. All rights reserved.