Hi Francesco,
I could not find the definition you mention:
As per definition "In RMI objects that implement the Remote interface are passed by reference. All other parameters are passed by copy "
However I did find in
the specification:
when an exported object of type UnicastRemoteObject is passed as a parameter or return value in an RMI call, the object is replaced by the remote object's stub. An exported remote object implementation remains in the virtual machine in which it was created and does not move (even by value) from that virtual machine. In other words, an exported remote object is passed by reference in an RMI call
Or, from the
RMI Tutorial:
The rules governing how arguments and return values are passed are as follows.
Remote objects are essentially passed by reference. A remote object reference is a stub, which is a client-side proxy that implements the complete set of remote interfaces that the remote object implements. Local objects are passed by copy, using object serialization. By default all fields are copied, except those that are marked static or transient. Default serialization behavior can be overridden on a class-by-class basis.
That last explanation is probably the simplest, and explains the problem you are seeing.
Just stating that class A implements Remote does not mean that it will be passed as an exported Remote object - since you have not exported it (as indicated by Oricio)
Java will revert to sending a copy of the
local A instance.
So lets convert your code to export A, which means that it will pass a remote object reference:
Now when we
test this, we can see that we get the same value on both client and server:
Regards, Andrew