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

编程入门 行业动态 更新时间:2024-10-21 15:39:00
本文介绍了我们什么时候应该实现 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接口?
  • 我们为什么要这样做?
  • 它有什么好处或安全性吗?
  • 推荐答案

  • 来自 这个序列化"是怎么回事?:

    它可以让你把一个物体或一组对象,将它们放在磁盘上或发送他们通过有线或无线运输机制,然后,也许在另一台计算机上,反向过程:复活原作对象.基本机制是将物体压平成一个一维比特流,以及将该比特流转回原始对象.

    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).

    就像星际迷航中的运输车一样,一切都是为了拿东西复杂,把它变成一个公寓1 和 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:21:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/568545.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:什么时候   接口   Serializable

    发布评论

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

    >www.elefans.com

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