public class ConstructorUtils
extends java.lang.Object
| Constructor and Description |
|---|
ConstructorUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.lang.reflect.Constructor<T> |
getAccessibleConstructor(java.lang.reflect.Constructor<T> ctor)
Checks if the specified constructor is accessible.
|
static <T> java.lang.reflect.Constructor<T> |
getMatchingAccessibleConstructor(java.lang.Class<T> cls,
java.lang.Class<?>... parameterTypes)
Finds an accessible constructor with compatible parameters.
|
public static <T> java.lang.reflect.Constructor<T> getAccessibleConstructor(java.lang.reflect.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 foundjava.lang.NullPointerException - if ctor is nullSecurityManagerpublic static <T> java.lang.reflect.Constructor<T> getMatchingAccessibleConstructor(java.lang.Class<T> cls,
java.lang.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 parametersjava.lang.NullPointerException - if cls is null