开发者

Externalizable or Serializable?

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 开发者_Python百科Serializable interface only. can it be ignorance or Serializalable provides some other advantage which i am missing?


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.

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.


Serializable is a marker interface that indicates that instances can be written to an output stream and read back. You don't have to write and code (you just have to ensure all fields are themselves Serializable).

Externalizable is a Serializable that alos provides custom (de)serialization code.


I got to know Externalizable is better than Serializalable

That link doesn't say that. There is no 'better' in this situation, it is horses for courses. If you are prepared to write lots more code, continually over the lifetime of the project, Externalizable may be 'better' in some senses, e.g. space and time costs. If the cost of code is a concern, Serializable is a great deal 'better'. And these aren't the only alternatives.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜