java - 当可以通过重写 writeObject() 和 readObject() 进行自定义序列化时,java 外部化有什么用?

标签 java serialization serializable externalizable

我正在学习java序列化,我有一个疑问,如果可以通过重写类中的writeObject()和readObject()方法来自定义默认序列化过程,那么Externalized接口(interface)有什么用?什么场景下需要?

最佳答案

它用于自定义序列化,请参阅 Guide to the Externalizable

主要用途:

change the JVM’s default serialization behavior.

用例:

If we need to serialize the entire object, the Serializable interface is a better fit. On the other hand, for custom serialization, we can control the process using Externalizable.

可能的性能优势:

The java.io.Serializable interface uses reflection and metadata which causes relatively slow performance. By comparison, the Externalizable interface gives you full control over the serialization process.

关于java - 当可以通过重写 writeObject() 和 readObject() 进行自定义序列化时,java 外部化有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56965188/

相关文章:

c# - 反序列化二进制文件的一部分

java - 在 100 多个文件中实现序列化

java - where in 子句中没有值时如何执行查询

Java:使用getClass获取子类引用

c# - LINQ 序列化

c++ - 使用 boost 序列化、std::tr1::unordered_map 和自定义键的奇怪行为

c# - 具体 C# 类中是否需要可序列化属性?

java - "Serializable"接口(interface)背后的基本原理是什么?

java - Hibernate 在使用 Oracle 序列时不生成标识符

java - Xuggler是否生成RTSP流