RemoteObject 方法的返回对象是否必须是可序列化的? 例如,A是一个远程对象,具有以下功能:
SomeObject getMyObject() throws java.rmi.RemoteException
SomeObject 必须是可序列化的吗?
最佳答案
根据文档,它应该是:
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
这是有道理的。对象应从一个节点传输到另一节点。为了进行传输,它应该被放置在套接字中(在某个时刻),因此它应该被序列化。
关于java - RemoteObject方法返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14821548/