Java:什么可以和什么不能序列化? [英] Java: What can and what can't be serialized?

查看:548
本文介绍了Java:什么可以和什么不能序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 Serializable 界面只是一个使用的标记界面在java中传递关于类的某种元数据 - 我有点困惑:

If the Serializable interface is just a Marker-Interface that is used for passing some-sort of meta-data about classes in java - I'm a bit confused:

在阅读了java的序列化算法的过程之后(元数据从底部到 - 顶部,然后是从上到下的实际实例数据),我无法真正理解通过该算法处理不能的数据。

After reading the process of java's serialization algorithm (metadata bottom-to-top, then actual instance data top-to-bottom), I can't really understand what data cannot be processed through that algorithm.

简而言之:


  1. 哪些数据可能导致 NotSerializableException

  2. 我怎么知道我不应该为我的班级添加实现Serializable 子句?

  1. What data may cause the NotSerializableException?
  2. How should I know that I am not supposed to add the implements Serializable clause for my class?


推荐答案

当你在谈论 NotSerializableException 时当你想序列化一个没有被标记为 Serializable 的对象时抛出 - 这就是全部,尽管你扩展非可序列化的类,并添加可序列化的界面非常好。

When you are talking about NotSerializableException it is throw when you want to serialize an object, which has not been marked as Serializable - that's all, although when you extend non serializable class, and add Serializable interface it is perfectly fine.

没有数据无法序列化。

这篇关于Java:什么可以和什么不能序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆