为什么实现 Externalizable 需要一个默认的公共构造函数? [英] Why does implementing Externalizable need a default public constructor?

查看:48
本文介绍了为什么实现 Externalizable 需要一个默认的公共构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们正在实现 Serializable,我们就不需要它.那么为什么会有这种差异呢?它与序列化的实际机制有什么关系?

We don't need it if we're implementing Serializable. So why this difference? How does it relate to the actual mechanism of Serialization?

推荐答案

可以在 http://www.jusfortechies.com/java/core-java/externalization.php.简短的回答,以供将来参考,以防链接页面消失:

A thorough explanation (although the grammar of the article might be improved) can be found on http://www.jusfortechies.com/java/core-java/externalization.php . The short answer, for future reference in case the linked page goes away:

Externalizable 是扩展 Serializable 的接口.然而,与 Serializable 相反,对象不是通过读取序列化的字节流来恢复的,而是调用公共构造函数,并且只有在这样创建对象后,才会恢复其状态.这使得恢复更有效.

Externalizable is an interface extending Serializable. Contrary to Serializable, though, objects are not restored by just reading the serialized bytestream, but the public constructor is called and only once the object is thus created, its state is restored. This makes restoring more efficient.

另见 Java 中 Serializable 和 Externalizable 有什么区别? .

这篇关于为什么实现 Externalizable 需要一个默认的公共构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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