アプリケーションでReflectionAPIを使用したい。インターフェイスとその実装クラスがあり、すべてのメソッド宣言が示されています。
上記のコードにReflectionを使用する方法を教えてください。
クライアントクラスを書き始めましたが、これが正しいかどうかわかりませんか?メソッドを呼び出す方法を教えてください
で私を助けてください
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;
}
そして、示されている上記のインターフェースの実装クラス
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 {}
}
示されているようにクライアントクラスがあります
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 ??
}
}