public static < T > Constructor < T > findConstructor ( Class < T > cls , Class < ? > ... argTypes ) throws NoSuchMethodException { Constructor < T > ctor ; try { ctor = cls . getDeclaredConstructor ( argTypes ) ; } catch ( NoSuchMethodException e ) { throw e ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Unable to find constructor of class " + cls . getName ( ) + ", problem: " + e . getMessage ( ) , ExceptionUtils . getRootCause ( e ) ) ; } // must be public if ( ! Modifier . isPublic ( ctor . getModifiers ( ) ) ) { throw new IllegalArgumentException ( "Constructor for " + cls . getName ( ) + " is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type" ) ; } return ctor ; }
Obtain an accessible constructor for the given class and parameters .