为什么ObjectOutputStream.writeObject不采用Serializable? [英] Why does ObjectOutputStream.writeObject not take a Serializable?

查看:160
本文介绍了为什么ObjectOutputStream.writeObject不采用Serializable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 ObjectOutputStream.writeObject(Object o) 不能 Serializable ?为什么采用对象

推荐答案

这是因为 writeObject in ObjectOutputStream 覆盖方法 /docs/api/java/io/ObjectOutput.html\"rel =noreferrer> ObjectOutput 界面,不要求对象 Serializable

This is because writeObject in ObjectOutputStream overrides the method in the ObjectOutput interface which does not require that the object be Serializable.

ObjectOutput 接口指定允许对象的方法写入流或底层存储,但这可以通过序列化以外的过程实现。 ObjectOutputStream 实现了此功能,但需要可序列化的对象。但是,它无法修改它实现的接口的签名。

The ObjectOutput interface specifies methods that allow objects to be written to a stream or underlying storage, but this may be achieved by a process other than serialization. The ObjectOutputStream implements this functionality, but requires serializable objects. However, it cannot modify the signature of the interface that it implements.

这篇关于为什么ObjectOutputStream.writeObject不采用Serializable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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