Explain how to use Java reflection to construct a generic dispatcher. Give Java code for a dispatcher whose signature is:
```
public void dispatch(Object target, Method aMethod, byte[] args)
```
The arguments supply the target object, the method to be invoked and the arguments for that method in an array of bytes.
Use the class Method. To invoke a method supply the object to be invoked and an array of Object containing the arguments. The arguments supplied in an array of bytes must be converted to an array of Object.
```
public void dispatch(Object target, Method aMethod, byte[] args)
throws RemoteException {
Object[] arguments = // extract arguments from array of bytes
try{
aMethod.invoke(target, arguments);
catch(...){}
}
```
You might also like to view...
The preferred means of creating multithreaded Java applications is by implementing the ________ interface. An object of a class that implements this interface represents a task to perform.
a. Thread b. Runner c. Runnable d. None of the above.
In Chrome Device Mode, the maximum time from a request being sent to data being returned from the server is measured in __________.
A. milliseconds B. number of files C. megahertz (MHz) D. megabits per second (Mbps)