RMI:通过价值或参考? [英] RMI: Pass by Value or by Reference?

查看:113
本文介绍了RMI:通过价值或参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我正在创造一个多元化的垄断者游戏。实际的垄断代码在服务器上运行,客户端本质上是一个访问和控制此代码的GUI。垄断游戏由一个名为银行的类控制。

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'.

假设我在客户的main()中这样做了:

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

这会调用服务器上的Bank对象上的turn()吗?在我的本地机器上复制它?

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.

推荐答案

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

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.

编辑:由于 Bank 类不是远程,但 Serializable ,然后它将被复制并按值传递。

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

这篇关于RMI:通过价值或参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆