How to pass object in arguments in RMI method?

前端 未结 1 977
余生分开走
余生分开走 2021-01-06 12:38

I am trying to add arguments in RMI method. When I add e.g. String everything works fine. But I am not sure if I can pass an object I created. I am new to RMI s

相关标签:
1条回答
  • 2021-01-06 13:07

    Your object should implement Serializable. As I can see this would be one problem. It is needed because the communication between both parts is done using serialization, so each object that needs to be sent to the other part, needs to be an instance of class implementing Serializable.

    public class Context implements Serializable
    {
        private String requestType;
        private String distributedThreadName;
        private List<Long> IDList;
    
       (...) getters/setters
    }
    

    and please add a serialVersionUID as a good practice. Something like:

    private static final long serialVersionUID = 20120731125400L;
    
    0 讨论(0)
提交回复
热议问题