gpt4 book ai didi

java - 为什么 Java Bean 必须是可序列化的?

转载 作者:搜寻专家 更新时间:2023-10-30 19:53:23 27 4
gpt4 key购买 nike

Java Bean 是否有必要实现Serializable 接口(interface)?

最佳答案

这是 Javabeans specification 中描述的“典型”功能之一.

这是 2.1 什么是 bean? 章节的摘录

Individual Java Beans will vary in the functionality they support, but the typical unifying features that distinguish a Java Bean are:

  • Support for “introspection” so that a builder tool can analyze how a bean works
  • Support for “customization” so that when using an application builder a user can customize the appearance and behaviour of a bean.
  • Support for “events” as a simple communication metaphor than can be used to connect up beans.
  • Support for “properties”, both for customization and for programmatic use.
  • Support for persistence, so that a bean can be customized in an application builder and then have its customized state saved away and reloaded later.

下面是 5.5 持久性总结一章的摘录:

All beans must support either Serialization or Externalization.

在实践中,它的运行并不是明确必需的。它通常也可以在不实现 Serializable 的情况下正常工作.然而,每当您想将它们“纯文本”存储在硬盘上或通过网络发送“纯文本”时,它就很有用。例如,当它是一个 session 范围的 bean,它将被存储在 HTTP session 中,并且服务器被配置为在关闭/重启期间保持和恢复 HTTP session 。无论如何,每当你面对 NotSerializableException在消息中使用 bean 的完全限定类名,那么它就足以让它实现 Serializable

关于java - 为什么 Java Bean 必须是可序列化的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3142181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com