0

Does a RemoteObject method's return object has to be a serializable? For example, A is a remote object and has the function:

SomeObject getMyObject() throws java.rmi.RemoteException

does SomeObject have to be serializable?

user000001
  • 32,226
  • 12
  • 81
  • 108
TheNotMe
  • 1,048
  • 2
  • 17
  • 33

2 Answers2

3

Well according to the docs it should be:

2.6 Parameter Passing in Remote Method Invocation

An argument to, or a return value from, a remote object can be any object that is serializable. This includes primitive types, remote objects, and non-remote objects that implement the java.io.Serializable interface. For more details on how to make classes serializable, see the "Java Object Serialization Specification." Classes, for parameters or return values, that are not available locally are downloaded dynamically by the RMI system. See the section on "Dynamic Class Loading" for more information on how RMI downloads parameter and return value classes when reading parameters, return values and exceptions.

http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/spec/rmi-objmodel7.html

And this makes sense. The Object should transmitted from one node to the other. In order to be transmitted, it should be placed in a socket (at some point), so it should serialized.

user000001
  • 32,226
  • 12
  • 81
  • 108
  • Does that include primitive types? I mean, do primitive types actually implement java.io.serializable? – TheNotMe Feb 11 '13 at 22:18
  • Primitive types are serializable, in that the JVM knows how to convert them into a stream of bits, but they cannot implement any interface, since they are not Objects. – user000001 Feb 11 '13 at 22:23
  • Note that the quotation doesn't say it must be Serializable. It says it must be 'any object that is *serializable.*` It isn't the same thing, as the quotation goes on to make clear. – user207421 Feb 12 '13 at 00:28
1

It must either be a primitive type, a Serializable type, or an exported remote object itself. In the latter case it is automatically converted to a Stub. Registry.lookup() is an example.

user207421
  • 305,947
  • 44
  • 307
  • 483