public final class ReflectionHelper
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.reflect.Method |
findMethod(java.lang.Class c,
java.lang.String name,
java.lang.Object... params)
Searches for a method by its name and arguments.
|
static <T> java.lang.Class<T> |
getClass(java.lang.String name)
Load class by name, wrapping a
ClassNotFoundException into unchecked exception. |
static java.lang.Class[] |
getParamTypes(java.lang.Object... params)
Constructs an array of argument types from an array of actual values.
|
static <T> T |
invokeMethod(java.lang.Object obj,
java.lang.String name,
java.lang.Object... params)
Invokes a method by reflection.
|
static java.lang.Class<?> |
loadClass(java.lang.String name)
Load class by name.
|
static <T> T |
newInstance(java.lang.Class<T> cls,
java.lang.Object... params)
Instantiates an object by appropriate constructor.
|
public static java.lang.Class<?> loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
name
- class FQN or primitive type namejava.lang.ClassNotFoundException
- if not foundpublic static <T> java.lang.Class<T> getClass(java.lang.String name)
ClassNotFoundException
into unchecked exception.name
- class FQNpublic static <T> T newInstance(java.lang.Class<T> cls, java.lang.Object... params) throws java.lang.NoSuchMethodException
cls
- classparams
- constructor argumentsjava.lang.NoSuchMethodException
- if the class has no constructor matching the given arguments@Nullable public static java.lang.reflect.Method findMethod(java.lang.Class c, java.lang.String name, java.lang.Object... params)
c
- classname
- method nameparams
- method argumentspublic static <T> T invokeMethod(java.lang.Object obj, java.lang.String name, java.lang.Object... params) throws java.lang.NoSuchMethodException
obj
- object instancename
- method nameparams
- method argumentsjava.lang.NoSuchMethodException
- if a suitable method not foundpublic static java.lang.Class[] getParamTypes(java.lang.Object... params)
params
- arguments