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