Class ConstructorUtils


  • public class ConstructorUtils
    extends Object
    Imported from apache.commons.lang3 3.6
    • Constructor Detail

      • ConstructorUtils

        public ConstructorUtils()
    • Method Detail

      • getAccessibleConstructor

        public static <T> Constructor<T> getAccessibleConstructor​(Constructor<T> ctor)
        Checks if the specified constructor is accessible.

        This simply ensures that the constructor is accessible.

        Type Parameters:
        T - the constructor type
        Parameters:
        ctor - the prototype constructor object, not null
        Returns:
        the constructor, null if no matching accessible constructor found
        Throws:
        NullPointerException - if ctor is null
        See Also:
        SecurityManager
      • getMatchingAccessibleConstructor

        public static <T> Constructor<T> getMatchingAccessibleConstructor​(Class<T> cls,
                                                                          Class<?>... parameterTypes)
        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.

        Type Parameters:
        T - the constructor type
        Parameters:
        cls - the class to find a constructor for, not null
        parameterTypes - find method with compatible parameters
        Returns:
        the constructor, null if no matching accessible constructor found
        Throws:
        NullPointerException - if cls is null