public final class ReflectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Method |
findMethod(Class<?> clazz,
String name)
Attempt to find a
Method on the supplied class with the supplied
name and no parameters. |
static Method |
findMethod(Class<?> clazz,
String name,
Class<?>... paramTypes)
Attempt to find a
Method on the supplied class with the supplied
name and parameter types. |
static <T> Constructor<T> |
getConstructor(Class<T> clazz,
Object... objs)
Returns a constructor that contains
objs as arguments. |
public static Method findMethod(Class<?> clazz, String name)
Method
on the supplied class with the supplied
name and no parameters. Searches all superclasses up to
Object
.
Returns null
if no Method
can be found.
clazz
- the class to introspectname
- the name of the methodnull
if none foundpublic static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
Method
on the supplied class with the supplied
name and parameter types. Searches all superclasses up to
Object
.
Returns null
if no Method
can be found.
clazz
- the class to introspectname
- the name of the methodparamTypes
- the parameter types of the method (may be null
to
indicate any signature)null
if none foundpublic static <T> Constructor<T> getConstructor(Class<T> clazz, Object... objs) throws NoSuchMethodException
objs
as arguments.
We could not do something like clazz.getConstructor(objs.class())
because that would require casting all the passed arguments to the exact
parameter types of the desired constructor.
objs
- list of arguments of the constructorobjs
NoSuchMethodException
- when the constructor with args
does not exist or is
ambiguousCopyright © 2003-2013 OFFIS, Henri Tremblay. All Rights Reserved.