I have read various articles about passing variables around using RMI. Some of them
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Important note: if pass by reference means modifying argument value inside the method and change original variable in caller, you can’t. If what you want to do is passing a copy of a reference to an object, to allow the method interact with some object of yours… yes you can. The answer explores that second option.
Yes. But it has to be an RMI object. In that case a RMI stub will be passed by copy.
RMI passes arguments and return values two ways:
Sample
Guess we have a Service. It’s a RMI object, published through the RMI registry, so it’s accesible to clients. Client can call a method on it (to create something) and the service wants to return a reference to that newly created object. Not a serialized copy but a reference to the created object in server memory space.
In this example you could:
Create an implementation of MyService and publish it
and then, some RMI client could get a reference to it
and with a reference to the service object could obtain a reference to other RMI object.
In this example the method argument is serialized (it should be a Serializable class)
while the returned object is a RMI reference to an object created in the server.
The implementation of createX(…) could be: