为什么java RMI不能通过引用获取返回值 [英] why java RMI can't get return value by reference
问题描述
在RMI中,我只能通过
In RMI, I can only get return value by
InetSocketAddress address = new InetSocketAddress(hostname, port);
Server server = Stub.create(Server.class, address);
int return = server.getValue();
但是,我无法得到它
public class Return {
int value;
}
InetSocketAddress address = new InetSocketAddress(hostname, port);
Server server = Stub.create(Server.class, address);
Return return = new Return();
server.getValue(return);
我知道参数会被序列化和反序列化,但这不是我的问题,我的问题是为什么 Java 不能像在 C 中使用 RPC 那样模拟传递引用作为传递输入输出?",我觉得跟java环境有关.通过输入输出我的意思是在带有 RPC 的 C 中,您可以通过
I know arguments will be serialized and deserialized, but that's not my question, my question is "why can't Java emulate a pass-by-reference as a pass by in-out, as was done in C with RPC?", I think it's related to java environment. By in-out I mean in C with RPC, you can get return value by
int return;
rpc.getValue(&return);
希望现在我的问题很清楚了.
Hope now my question is clear.
推荐答案
返回额外的对象代理会带来实施挑战.就目前情况而言,只有一种方法可以创建远程对象.如果允许方法仅通过返回常规对象来产生更多远程对象,那么所有这些调用都需要被拦截,对象正确编目等.
Returning additional object proxies would pose an implementation challenge. As things stand, there's only one way to create a remote object. if methods are allowed to spawn more remote objects just by returning regular objects, then all those calls need to be intercepted, objects properly catalogued, etc.
换句话说,Java 人 - 不像,e.G.DCOM 人 - 决定不做额外的管道.这将永远是为什么系统 A 与系统 B 不同"问题的答案.
In other words, the Java people - unlike , e. g. DCOM people - decided not to do the extra plumbing. And that will always be the answer to the "why is system A unlike system B" quesions.
这篇关于为什么java RMI不能通过引用获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!