简体   繁体   中英

RMI: Pass by Value or by Reference?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM