Static data members not sent in Object Send via Sockets

前端 未结 1 1817
再見小時候
再見小時候 2021-01-23 15:32

I want to send the same object for two clients. I use object write unshared method and read unshared. The class of my object is:

package servidor;

import java.i         


        
1条回答
  •  后悔当初
    2021-01-23 16:16

    When you serialize an object, your only serialize the fields of that object, not static fields. You could serialize static fields by adding writeObject and readObject but this is generally a very bad idea.

    I suggest you avoid using mutable static fields in general for multiple reasons, this being just one of them. In this case it would fix your problem.

    0 讨论(0)
提交回复
热议问题