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 Class<?> |
getClass(ClassLoader classLoader,
String className)
Get the named
Class from the specified ClassLoader . |
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 boolean |
setAccessible(AccessibleObject o,
boolean accessible)
Set the accessibility of
o to accessible . |
public static Class<?> getClass(ClassLoader classLoader, String className) throws Exception
Class
from the specified ClassLoader
.classLoader
- className
- Exception
public static Object getAnnotationValue(Annotation annotation, String name) throws IllegalAccessException, InvocationTargetException
Annotation
.annotation
- name
- IllegalAccessException
InvocationTargetException
public static ClassLoader getClassLoader(Class<?> clazz)
clazz
- ClassLoader
public static Field getDeclaredField(Class<?> clazz, String fieldName)
clazz
.clazz
- fieldName
- Field
or null
public static Field[] getDeclaredFields(Class<?> clazz)
clazz
- Field
arraypublic static <T> Constructor<T> getDeclaredConstructor(Class<T> clazz, Class<?>... parameters)
clazz
.T
- generic typeclazz
- parameters
- Constructor
or null
public static Method getDeclaredMethod(Class<?> clazz, String name, Class<?>... parameters)
clazz
.clazz
- name
- parameters
- Method
or null
public 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 null
public 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–2019 The Apache Software Foundation. All rights reserved.