为什么一个类实现了Serializable接口?

编程入门 行业动态 更新时间:2024-10-19 15:29:47
本文介绍了为什么一个类实现了Serializable接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 @Entity public class Husband implements Serializable { @Id private int id; private String name; @OneToOne private Wife wife; } @Entity public class Wife implements Serializable { @Id private int id; private String name; @OneToOne(mappedBy="wife") private Husband husband; }

  • 什么是 Serializable 从广义上讲?
  • 为什么一个类实现 Serializable interface?
  • 为什么丈夫成员单独拥有@OnetoOne(mappedBy =妻子),但妻子成员没有@OnetoOne(mappedBy =丈夫)
  • What is Serializable in broad term?
  • Why does a class implements Serializable interface?
  • Why does the husband member alone have @OnetoOne(mappedBy ="Wife"), but the wife member does not have @OnetoOne(mappedBy="husband")
  • 推荐答案

  • 从广义上讲,序列化是Java为开发人员提供持久保存状态的方式任何对象到持久性存储的情况。

  • Serialization, in broad terms, is the way Java provides developers to persist the state of any object to a persistent store.

    如果开发人员想要由于某种原因将其编码类的实例持久化到后备存储,那么该类需要声明为实现Serializable。

    If a developer wants that for some reason instance of his coded class should be persisted to a backing store, then the class needs to be declared as implementing Serializable.

    上述代码表示丈夫和妻子之间的一对一关系。这基本上意味着每个妻子与一个丈夫有关,每个丈夫与一个妻子有关。 :-)同样在上述关系中,丈夫是[实体 - 关系条款]中的关系的主人,这就是为什么妻子说它被丈夫映射/关联到丈夫而不是相反的方式。这意味着丈夫识别其妻子,而不是相反。

    The above code represents a One to One relationship between a Husband and a Wife. Which basically means that each wife is related to one husband and each husband is related to one wife. :-) Also in the above relationship, the Husband is the master of the relationship [in Entity-Relationship terms] and that is why Wife says that it is mapped/associated to Husband by the Husband and not the other way around. Which means Husband identifies its wife and not the other way around.

  • 更多推荐

    为什么一个类实现了Serializable接口?

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

    发布评论

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

    >www.elefans.com

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