When should we implement Serializable interface?

后端 未结 3 474
闹比i
闹比i 2020-12-02 04:20
public class Contact implements Serializable {
    private String name;
    private String email;

    public String getName() {
        return name;
    }

    publ         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 04:28

    1. Implement the Serializable interface when you want to be able to convert an instance of a class into a series of bytes or when you think that a Serializable object might reference an instance of your class.

    2. Serializable classes are useful when you want to persist instances of them or send them over a wire.

    3. Instances of Serializable classes can be easily transmitted. Serialization does have some security consequences, however. Read Joshua Bloch's Effective Java.

提交回复
热议问题