Again, can only obtain instances of this class through Class::getMethod().
If there is a bad argument to invoke(), a NullPointer/ IllegalArgument/
IllegalAccessException is thrown. If the underlying method, however, throws some
exception, then that exception is caught by invoke() and wrapped in an
InvocationTargetException which is then thrown by invoke. Thus, to
handle exceptions thrown by the underlying method, the caller must catch the
InvocationTargetException and then use getTargetException() and instanceof
to determine what exception it was.
Implementation: the class contains private variables:
private Class clazz; // declaring class
private int slot; // ???
private String name; // name of method
private Class returnType; // ...
private Class[] parameterTypes;
private Class[] exceptionTypes;
private int modifiers;
The invoke() method is native. It sets up the stack, frame, etc. and executes the method code.