public class ConstructorUtils extends Object
| Constructor and Description |
|---|
ConstructorUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Constructor<T> |
getAccessibleConstructor(Constructor<T> ctor)
Checks if the specified constructor is accessible.
|
static <T> Constructor<T> |
getMatchingAccessibleConstructor(Class<T> cls,
Class<?>... parameterTypes)
Finds an accessible constructor with compatible parameters.
|
public static <T> Constructor<T> getAccessibleConstructor(Constructor<T> ctor)
This simply ensures that the constructor is accessible.
T - the constructor typector - the prototype constructor object, not nullnull if no matching accessible constructor foundNullPointerException - if ctor is nullSecurityManagerpublic static <T> Constructor<T> getMatchingAccessibleConstructor(Class<T> cls, Class<?>... parameterTypes)
This checks all the constructor and finds one with compatible parameters This requires that every parameter is assignable from the given parameter types. This is a more flexible search than the normal exact matching algorithm.
First it checks if there is a constructor matching the exact signature. If not then all the constructors of the class are checked to see if their signatures are assignment-compatible with the parameter types. The first assignment-compatible matching constructor is returned.
T - the constructor typecls - the class to find a constructor for, not nullparameterTypes - find method with compatible parametersNullPointerException - if cls is null