可外部化或可序列化? [英] Externalizable or Serializable?

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

问题描述

浏览 http:// geekexplains。 blogspot.com/2008/06/diff-between-externalizable-and.html ,我知道Externalizable比Serializalable更好,因为它提供了更好的代码控制,也更快.So Externalizable应该是优先的而不是Serializable提供的类定义没有改变。但是当我在任何项目中看到时,我发现只使用Serializable接口。它是无知还是Serializalable提供了一些我缺少的其他优势?

After going through the article at http://geekexplains.blogspot.com/2008/06/diff-between-externalizable-and.html, i got to know Externalizable is better than Serializalable as it provides better control on code and also faster .So Externalizable should be preffered instead of Serializable provided class definition is not changed.But when i see in any project i find using Serializable interface only. can it be ignorance or Serializalable provides some other advantage which i am missing?

推荐答案

Serializable的优势在于它非常容易实现,并且有弹性来改变(在大多数情况下,你所要做的就是更新serialversionUID)。 Externalizable要求程序员实际工作,并且每次类的内容发生变化时都要做更多的工作。正如您链接的文章指出实现Externalizable也容易出错。因此,从利用有限程序员时间的角度来看,Serializable通常是更好的选择。

The advantage of Serializable is it's incredibly easy to implement, and resilient to change (in most cases all you have to do is update the serialversionUID). Externalizable requires the programmer to actually do work, and do more work every time the contents of the class change. As the article you link to points out implementing Externalizable is also error-prone. So from the point of view of utilizing limited programmer time, often Serializable is a better choice.

关于如何设计Serializable和Externalizable的好处是你可以推迟实施Externalizable的决定,直到明显存在性能问题为止,你可以有选择地实现它仅适用于存在问题的课程。

The good thing about how Serializable and Externalizable are designed is that you can defer the decision to implement Externalizable until it becomes evident there's a performance problem, and you can selectively implement it only for those classes where there's a problem.

这篇关于可外部化或可序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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