本文介绍了Java中的Serializable - writeObject()/ ReadObject和Externalizable - readExternal()/ writeExternal()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从帖子中了解到
Serializable非常容易实现,并且适应变化(在大多数情况下,您需要做的就是更新serialversionUID)。如果我们想控制读写过程,我们可以实现Externalizable。

I understood from this posting that Serializable is incredibly easy to implement, and resilient to change (in most cases all you have to do is update the serialversionUID). If we want to control of read and write process we can implement Externalizable.

如果我们只想控制读写过程,我们可以覆盖下面的序列化方法吗?为什么我们需要引入新的Externalizable接口?

If all we want is the control of read and write process, we can override the below methods for serialization right? why do we need to introduce the new interface Externalizable?

private void writeObject(java.io.ObjectOutputStream out)
     throws IOException
 private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException;
 private void readObjectNoData()
     throws ObjectStreamException;


推荐答案

你问:

我能找到的最佳理由(在Oracle文档中)位于文档:

The best rationale I've been able to find (in Oracle documentation) is in the WebLogic JMS Best Practice document:

简而言之,使用<$可以获得更好的性能c $ c> Externalizable ,至少在某些情况下。

In short, you can get better performance using Externalizable, at least in some situations.

差异是如果你使用序列化序列化工作通常是为您完成的,但是使用 Externalizable ,您需要自己编写代码。

And "the difference" is that if you use Serializable the work of serialization is typically done for you, but with Externalizable you need to code it yourself.

这篇关于Java中的Serializable - writeObject()/ ReadObject和Externalizable - readExternal()/ writeExternal()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:29