3 Replies Latest reply: Aug 24, 2010 8:19 PM by EJP RSS

    What is the point of having all RMI server classes be Serializable?

    843793
      I've confirmed that the serialVersionUID of the class is not the serialVersionUID of the generated stub. The class itself is never serialized and its fields don't need to be Serializable or transient. It is annoying me that Netbeans is giving me warnings about not defining serialVersionUID when there is clearly no point in doing so. So why does java.rmi.server.RemoteObject implement Serializable?
        • 1. Re: What is the point of having all RMI server classes be Serializable?
          EJP
          I've confirmed that the serialVersionUID of the class is not the serialVersionUID of the generated stub.
          No reason why it should be.
          The class itself is never serialized
          See below.
          So why does java.rmi.server.RemoteObject implement Serializable?
          RemoteObject is the base class for RemoteStub which certainly is serialized: that's the entire basis for RMI's operation.

          A remote object is also passed by serialization rather than by remote reference when it isn't exported.

          As for NetBeans ...
          • 2. Re: What is the point of having all RMI server classes be Serializable?
            843793
            RemoteStub is one thing, why does everything that extends UnicastRemoteObject need to be Serializable? What do you mean "A remote object is also passed by serialization rather than by remote reference when it isn't exported." ? In theory a remote object can be serialized just like any object can be serialized, but in those cases you would explicitly make it Serializable yourself. There is no reason to expect that all remote objects need to be Serializable.
            • 3. Re: What is the point of having all RMI server classes be Serializable?
              EJP
              What do you mean "A remote object is also passed by serialization rather than by remote reference when it isn't exported."?
              If your remote method passes or returns a remote object that isn't currently exported, it is serialized, instead of being passed/returned via its stub as a remote reference. See the [RMI Specification #2.6.2|http://download.oracle.com/javase/6/docs/platform/rmi/spec/rmi-objmodel7.html]. This is the reason to expect that all remote objects are serializable.