public class Reflection extends Object
| Modifier and Type | Field and Description |
|---|---|
static Object[] |
NO_ARGS
Constant defining an empty argument array for methods or constructors.
|
| Modifier and Type | Method and Description |
|---|---|
static Object[] |
asArgs(Object... args)
Returns the specified objects as an array of arguments.
|
static Class<?> |
boxingClass(Class<?> type)
Returns the class boxing the specified primitive type.
|
static <TYPE> Constructor<TYPE> |
findConstructor(Class<TYPE> type,
Object... args)
Finds the constructor of the specified class best matching the passed arguments.
|
static Method |
findMethod(Class<?> type,
String name,
Class<?>... parameterTypes)
Finds the method matching the specified parameters.
|
static boolean |
hasStaticContext(Class<?> type)
Checks if the specified class is static or is a top level class.
|
static Constructor<?> |
makeAccessible(Constructor<?> constructor)
Makes the specified constructor accessible.
|
static Method |
makeAccessible(Method method)
Makes the specified method accessible.
|
public static final Object[] NO_ARGS
@NotNull public static Object[] asArgs(@Nullable Object... args)
args - the argument objects.@NotNull public static Class<?> boxingClass(@NotNull Class<?> type)
type - the primitive type.@NotNull public static <TYPE> Constructor<TYPE> findConstructor(@NotNull Class<TYPE> type, @NotNull Object... args)
TYPE - the target type.type - the target class.args - the constructor arguments.IllegalArgumentException - if no constructor taking the specified objects as
parameters was found.@NotNull public static Method findMethod(@NotNull Class<?> type, @NotNull String name, @NotNull Class<?>... parameterTypes)
type - the target class.name - the method name.parameterTypes - the method parameter types.IllegalArgumentException - if no method matching the specified parameters was
found.public static boolean hasStaticContext(@NotNull
Class<?> type)
type - the class.@NotNull public static Constructor<?> makeAccessible(@NotNull Constructor<?> constructor)
constructor - the constructor instance.