I want to use Reflection API in my Application .
I have a Interface and its implementation class , with all the Method declartions as shown .
Please let me know how can i Use Reflection for the above code .
I have started writing client class , but i am not sure if this is right or not ?? Please let me know how can i invoke the method
Please help me in
public interface DataHandler extends Remote {
public abstract String logon(String message) throws RemoteException;
public abstract String logoff(String message) throws RemoteException;
public abstract String userinformation(String message) throws RemoteException;
public abstract String updateUser(String message) throws RemoteException;
}
And an implementation class for the above interface as shown
public class CodeHandler implements DataHandler
{
public String logon(String message) throws RemoteException {}
public String logoff(String message) throws RemoteException {}
public String userinformation(String message) throws RemoteException {}
public String updateUser(String message) throws RemoteException {}
}
I have a client class as shown
public class Client
{
public static void main(String args[])
{
callMethod("logon");
}
private Object callMethod(String message) {
String methodName = message ;
Method method = DataHandler.class.getDeclaredMethod(methodName, null);
method.setAccessible(true);
// How to use method.invoke in this case ??
}
}
I can see that your interface extends
java.rmi.Remote, so I guess you have to use the RMI facility instead of reflection here, but if you really need to use reflection try something like this: