public final class ReflectUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Constructor<T> |
findConstructor(Class<T> clazz,
Class<?>... params)
Tries to find a constructor that is able to accept parameters of the given types.
|
static Method |
findMatchingMethod(Class<?> clazz,
String name,
Object... args)
|
static Method |
findMethod(Class<?> clazz,
String name,
Class<?>... params)
Tries to find a method of the given name that is able to accept parameters of the given types.
|
static Method |
findMethodRT(Class<?> clazz,
String name,
Class<?> returnType,
Class<?>... params)
|
public static <T> Constructor<T> findConstructor(Class<T> clazz, Class<?>... params)
Constructor(int) would be returned for the parameters class Integer.class.
Returns null if no such constructor could be found.
T - the class typeclazz - the class which should be scanned for constructorsparams - the types of the constructor argumentsnull if such a
constructor could not be found.public static Method findMethod(Class<?> clazz, String name, Class<?>... params)
Method(int) would be returned for the parameters class Integer.class.
Returns null if no such method could be found.
clazz - the class which should be scanned for methodsname - the name of the methodparams - the types of the method argumentsnull if such a method could
not be found.public static Method findMatchingMethod(Class<?> clazz, String name, Object... args)
findMethod(Class, String, Class...). This variation does not required the types of input parameters,
but can handle the actual objects, which should be passed to the method.clazz - the class which should be scanned for methodsname - the name of the methodargs - the objects that should be passed to the methodnull if such a method could not be
found.public static Method findMethodRT(Class<?> clazz, String name, Class<?> returnType, Class<?>... params)
findMethod(Class, String, Class...). This variation allows to additionally narrow the method by
specifying its return type.clazz - the class which should be scanned for methodsname - the name of the methodreturnType - the type of the returned objectparams - the types of the method argumentsnull if such a method could not be
found.Copyright © 2019. All rights reserved.