public final class ReflectUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> @Nullable Constructor<T> |
findConstructor(Class<T> clazz,
Class<?>... params)
Tries to find a constructor that is able to accept parameters of the given types.
|
static @Nullable Method |
findMatchingMethod(Class<?> clazz,
String name,
Object... args)
|
static @Nullable 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 @Nullable Method |
findMethodRT(Class<?> clazz,
String name,
@Nullable Class<?> returnType,
Class<?>... params)
|
public static <T> @Nullable 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 @Nullable 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 @Nullable 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 method, may contain nullsnull if such a method could not be
found.public static @Nullable Method findMethodRT(Class<?> clazz, String name, @Nullable 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 object, if null, the return type will be ignoredparams - the types of the method argumentsnull if such a method could not be
found.Copyright © 2020. All rights reserved.