MethodUtils.
There is an issue when invoking public constructors contained in a default access superclass. Reflection correctly locates these constructors and
assigns them as public. However, an IllegalAccessException is thrown if the constructor is invoked.
ConstructorUtils contains a workaround for this situation: it will attempt to call java.
on this constructor. If this call succeeds, then the method can be invoked as normal. This call will only succeed when the application has sufficient
security privileges. If this call fails then a warning will be logged and the method may fail.
| Access | Constructor and Description |
|---|---|
| public | ConstructorUtils()
Deprecated
TODO Make private in 4.0.
ConstructorUtils instances should NOT be constructed in standard programming. |
| Modifier and Type | Method and Description |
|---|---|
| public static < the constructor type. T> Constructor | Returns: the constructor,null if no matching accessible constructor found.the class to find a constructor for, not cls, final Class<?>... null.the array of parameter types, parameterTypes)null treated as empty.Finds a constructor given a class and signature, checking accessibility. |
| public static < the constructor type. T> Constructor | Returns: the constructor,null if no matching accessible constructor found.the prototype constructor object, not ctor)null.Checks if the specified constructor is accessible. |
| public static < the constructor type. T> Constructor | Returns: the constructor, null if no matching accessible constructor found.the class to find a constructor for, not cls, final Class<?>... null.find method with compatible parameters. parameterTypes)Finds an accessible constructor with compatible parameters. |
| public static < the type to be constructed. T> T | Returns: new instance ofcls, not null.the class to be constructed, not cls, final Object... null.the array of arguments, args)null treated as empty.Returns a new instance of the specified class inferring the right constructor from the types of the arguments. |
| public static < the type to be constructed. T> T | Returns: new instance ofcls, not nullthe class to be constructed, not cls, final Object[] null.the array of arguments, args, final Class<?>[] null treated as empty.the array of parameter types, parameterTypes)null treated as empty.Returns a new instance of the specified class choosing the right constructor from the list of parameter types. |
| public static < the type to be constructed. T> T | Returns: new instance ofcls, not null.the class to be constructed, not cls, final Object... null.the array of arguments, args)null treated as empty.Returns a new instance of the specified class inferring the right constructor from the types of the arguments. |
| public static < the type to construct. T> T | Returns: new instance ofcls, not null.the class to construct, not cls, final Object[] null.the array of arguments, args, final Class<?>[] null treated as empty.the array of parameter types, parameterTypes)null treated as empty.Returns a new instance of the specified class choosing the right constructor from the list of parameter types. |
| private static boolean | Returns: true if type and any enclosing classes are public.to check. type)Tests whether the specified class is generally accessible, i.e. is declared in an entirely |
| ConstructorUtils | back to summary |
|---|---|
| public ConstructorUtils()
Deprecated TODO Make private in 4.0. ConstructorUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
This constructor is
| |
| getAccessibleConstructor | back to summary |
|---|---|
| public static <T> Constructor Finds a constructor given a class and signature, checking accessibility. This finds the constructor and ensures that it is accessible. The constructor signature must match the parameter types exactly.
| |
| getAccessibleConstructor | back to summary |
|---|---|
| public static <T> Constructor Checks if the specified constructor is accessible. This simply ensures that the constructor is accessible.
| |
| getMatchingAccessibleConstructor | back to summary |
|---|---|
| public static <T> Constructor Finds an accessible constructor with compatible parameters. 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.
| |
| invokeConstructor | back to summary |
|---|---|
| public static <T> T invokeConstructor(final Class<T> cls, final Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException Returns a new instance of the specified class inferring the right constructor from the types of the arguments. This locates and calls a constructor. The constructor signature must match the argument types by assignment compatibility.
| |
| invokeConstructor | back to summary |
|---|---|
| public static <T> T invokeConstructor(final Class<T> cls, final Object[] args, final Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException Returns a new instance of the specified class choosing the right constructor from the list of parameter types. This locates and calls a constructor. The constructor signature must match the parameter types by assignment compatibility.
| |
| invokeExactConstructor | back to summary |
|---|---|
| public static <T> T invokeExactConstructor(final Class<T> cls, final Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException Returns a new instance of the specified class inferring the right constructor from the types of the arguments. This locates and calls a constructor. The constructor signature must match the argument types exactly.
| |
| invokeExactConstructor | back to summary |
|---|---|
| public static <T> T invokeExactConstructor(final Class<T> cls, final Object[] args, final Class<?>[] parameterTypes) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException Returns a new instance of the specified class choosing the right constructor from the list of parameter types. This locates and calls a constructor. The constructor signature must match the parameter types exactly.
| |
| isAccessible | back to summary |
|---|---|
| private static boolean isAccessible(final Class<?> type) Tests whether the specified class is generally accessible, i.e. is declared in an entirely
| |