RMI + java reflection

心已入冬 提交于 2019-12-03 16:13:46
Erhard Dinhobl

The objects on your client are proxies: they are called stubs. To get the interfaces from it you should code something like this, where o is your object:

Class c = o.getClass();
Class[] theInterfaces = c.getInterfaces();
for (int i = 0; i < theInterfaces.length; i++) {
   String interfaceName = theInterfaces[i].getName();
   System.out.println(interfaceName);
}

Stubs are auto-generated: therefore you should not implement something into them, but you could implement a method getInformation() in your remote interfaces; every server object should implement this and return a string which contains all information of the server object. This method generates the string by getting information via reflection from the this object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!