public class Reflection extends Object
| Constructor and Description |
|---|
Reflection() |
| Modifier and Type | Method and Description |
|---|---|
static Object |
getAnnotationValue(Annotation annotation,
String name)
Get the named value from the specified
Annotation. |
static ClassLoader |
getClassLoader(Class<?> clazz)
|
static <T> Constructor<T> |
getDeclaredConstructor(Class<T> clazz,
Class<?>... parameters)
Get the declared constructor from
clazz. |
static Constructor<?>[] |
getDeclaredConstructors(Class<?> clazz) |
static Field |
getDeclaredField(Class<?> clazz,
String fieldName)
Get the declared field from
clazz. |
static Field[] |
getDeclaredFields(Class<?> clazz) |
static Method |
getDeclaredMethod(Class<?> clazz,
String name,
Class<?>... parameters)
Get the declared method from
clazz. |
static Method[] |
getDeclaredMethods(Class<?> clazz) |
static String |
getProperty(String name) |
static Method |
getPublicMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
|
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 boolean |
setAccessible(AccessibleObject o,
boolean accessible)
Set the accessibility of
o to accessible. |
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 getClassLoader(Class<?> clazz)
clazz - 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 Field getDeclaredField(Class<?> clazz, String fieldName)
clazz.clazz - fieldName - Field or nullpublic static Field[] getDeclaredFields(Class<?> clazz)
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)
clazz - Method arraypublic static Constructor<?>[] getDeclaredConstructors(Class<?> clazz)
clazz - Constructor arraypublic static Method getPublicMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
clazz - methodName - Method or nullpublic static <T> T newInstance(Class<T> cls)
cls using its default constructor.cls - public static boolean setAccessible(AccessibleObject o, boolean accessible)
o to accessible. If running without a SecurityManager
and accessible == false, this call is ignored (because any code could reflectively make any
object accessible at any time).o - accessible - Copyright © 2010–2025 The Apache Software Foundation. All rights reserved.