本文介绍了什么时候应该实现Serializable接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class Contact implements Serializable {
    private String name;
    private String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}




  1. 我应该何时实施 Serializable 界面?

  2. 为什么我们这样做?

  3. 它是否有任何优势或安全性?

  1. When should I implement Serializable interface?
  2. Why do we do that?
  3. Does it give any advantages or security?


推荐答案


  1. 来自:

就像星际迷航中的转运者一样,
所有这些都是关于将
复杂化并将其变为平坦的
序列的1s和0,然后取
序列1和0(可能在另一个地方
,可能在另一个
时间)并重建原始的
复杂的东西。

Like the Transporter on Star Trek, it's all about taking something complicated and turning it into a flat sequence of 1s and 0s, then taking that sequence of 1s and 0s (possibly at another place, possibly at another time) and reconstructing the original complicated "something."

因此,当您需要存储对象的副本时,实现 Serializable 界面,将它们发送到另一个在同一系统或网络上运行的进程。

So, implement the Serializable interface when you need to store a copy of the object, send them to another process which runs on the same system or over the network.

因为你想存储或发送一个对象。

Because you want to store or send an object.

它使存储和发送对象变得容易。它与安全性无关。

It makes storing and sending objects easy. It has nothing to do with security.

这篇关于什么时候应该实现Serializable接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:28