RMI: Pass by Value or by Reference?

旧街凉风 提交于 2019-12-01 23:54:31

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3087756/rmi-pass-by-value-or-by-reference

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