public static < T > Constructor < T > findKnownConstructor ( Class < T > aClass , Class < ? > ... paramTypes ) { try { return aClass . getConstructor ( paramTypes ) ; } catch ( NoSuchMethodException ex ) { // This cannot happen if the method is correctly identified. throw new IllegalArgumentException ( "Specified constructor does not exist in class " + aClass . getName ( ) , ex ) ; } }
Looks up a constructor that is explicitly identified . This method should only be used for constructors that definitely exist . It does not throw the checked NoSuchMethodException . If the constructor does not exist it will instead fail with an unchecked IllegalArgumentException .