RMI:按值传递还是按引用传递?

发布于 2024-09-06 23:00:13 字数 394 浏览 0 评论 0原文

我很难找到这个问题的明确答案,所以我想我应该在这里用我自己的具体例子来问:

我正在创建一个多人垄断游戏。实际的垄断代码在服务器上运行,而客户端本质上是一个访问和控制该代码的 GUI。垄断游戏由一个名为“银行”的类控制。

假设我在客户端的 main() 中执行了此操作:

Bank banker = server.getBank(); //gets the bank object from server
bank.turn(); //moves the current player

这会在服务器上的 Bank 对象上还是在我的本地计算机上的 Bank 对象的副本上调用 Turn() 吗?

更新:银行未实现远程。它是一个可序列化的对象。

I'm having trouble finding a clear answer to this question so I thought I'd ask here with my own specific example:

I am creating a mulitplayer monopoly game. The actual monopoly code runs on the server and the client is essentially a GUI which accesses and control this code. The monopoly game is controlled by a class called 'Bank'.

Say I did this in the main() of my client:

Bank banker = server.getBank(); //gets the bank object from server
bank.turn(); //moves the current player

Would this call turn() on the Bank object on the server or on a copy of it on my local machine?

Update: Bank does not implement remote. It is a serializable object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满意归宿 2024-09-13 23:00:13

这取决于 Bank 是否是 Remote 的实例。如果是这样,那么它将通过引用传递(如果所有设置都正确),如果不是,它将被序列化并按值传递。

编辑:由于您的Bank类不是Remote,但Serialized,那么它将被复制并按值传递。

That depends if Bank is an instance of Remote or not. If so, then it will be passed by reference (if all is set up correctly), if not it'll be serialized and passed by value.

edit: Since your Bank class is not Remote, but is Serializable, then it will be copied and passed by value.

善良天后 2024-09-13 23:00:13

这取决于你如何编码。

通常,代表服务器端对象的任何客户端对象都只需进行远程调用并更新服务器端对象。客户端对象只不过是用于调用服务器的传输协议的外观。

如果你使用了RMI,那么它就会遵循这个原则。

That depends on how you coded it.

Typically any client side objects that represent server side objects simply make remote calls with update the server side objects. The client side objects are nothing more than a facade over the transport protocols used to make the calls to the server.

If you used RMI, then it will follow this principle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文