Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RMI客户机&x27;无法转换为';例外_Java_Rmi - Fatal编程技术网

Java RMI客户机&x27;无法转换为';例外

Java RMI客户机&x27;无法转换为';例外,java,rmi,Java,Rmi,假设我有以下几行: Registry registry = LocateRegistry.getRegistry(2121); RemoteObject probe = (RemoteObject)registry.lookup(REMOTE_OBJ_NAME);//this throws exception probe.doSomething(); 例外情况如下: java.lang.ClassCastException:$Proxy1无法强制转换为app.RemoteObject 为清晰起

假设我有以下几行:

Registry registry = LocateRegistry.getRegistry(2121);
RemoteObject probe = (RemoteObject)registry.lookup(REMOTE_OBJ_NAME);//this throws exception
probe.doSomething();
例外情况如下:

java.lang.ClassCastException:$Proxy1无法强制转换为app.RemoteObject


为清晰起见,
RemoteObject
实现了一个扩展了
java.rmi.Remote
的接口,您需要将该接口转换为扩展的远程对象

RemoteInterface probe = (RemoteInterface)registry.lookup(REMOTE_OBJ_NAME);
probe.doSomething(); 

这是因为您永远不会返回实际对象,而是一个存根对象,它将任何方法调用转发给实际对象,您需要将其转换为扩展远程接口

RemoteInterface probe = (RemoteInterface)registry.lookup(REMOTE_OBJ_NAME);
probe.doSomething(); 

这是因为您永远不会返回实际对象,但是如果您的类实现了可序列化,则将任何方法调用转发给实际对象的存根对象不会扩展远程,也许是相同的:@Joe只是一个遥控器,它实现了原始对象的所有接口,也扩展了Remote@Joe它在异常中:
$Proxy1
registry.lookup
返回什么类型?类似的问题,也许是相同的:@Joe只是一个遥控器,它实现了原始对象的所有接口,也扩展了Remote@Joe例外情况是:
$Proxy1
。有人发表了同样建议的评论。问题解决了!有人发表了一篇评论,提出了同样的建议。问题解决了!(a) 为什么不呢?(b) 没有回答这个问题。(a)为什么不呢?(b) 没有回答这个问题。