我正在学习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/