什么时候应该实现Serializable接口?

编程入门 行业动态 更新时间:2024-10-20 03:53:22
本文介绍了什么时候应该实现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; } }

  • 我应该何时实施 Serializable 界面?
  • 为什么我们这样做?
  • 它是否有任何优势或安全性?
  • When should I implement Serializable interface?
  • Why do we do that?
  • Does it give any advantages or security?
  • 推荐答案

  • 来自这个序列化的内容是什么?:

    它允许你获取一个对象或一组对象,将它们放在磁盘上或通过有线或无线传输机制发送,然后再用另一个计算机,反向过程:恢复原来的对象。基本机制是将将对象展平为一维比特流,并将转换回原始对象的比特流。

    It lets you take an object or group of objects, put them on a disk or send them through a wire or wireless transport mechanism, then later, perhaps on another computer, reverse the process: resurrect the original object(s). The basic mechanisms are to flatten object(s) into a one-dimensional stream of bits, and to turn that stream of bits back into the original object(s).

    就像星际迷航中的转运者一样,所有这些都是关于将复杂化并将其变为平坦的序列的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接口?

    本文发布于:2023-06-07 15:20:35,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/568534.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:什么时候   接口   Serializable

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!