Java序列化,writeObject(Object obj)为什么不writeObject(Serializable obj)(Java Serialization, writeObject(Obj

编程入门 行业动态 更新时间:2024-10-26 04:30:34
Java序列化,writeObject(Object obj)为什么不writeObject(Serializable obj)(Java Serialization, writeObject(Object obj) why not writeObject(Serializable obj))

ObjectOutputStream的写方法的方法签名是

public final void writeObject(Object obj) throws IOException

由于obj应该实现Serializable (了解标记)。 为什么Java开发人员不会将此方法编写为

public final void writeObject(Serializable obj) throws IOException

有什么理由吗?

The method signature of ObjectOutputStream's write method is

public final void writeObject(Object obj) throws IOException

As obj should implements Serializable (know about markers). Why java developers do not write this method as

public final void writeObject(Serializable obj) throws IOException

is there any reason ?

最满意答案

writeObject在ObjectOutput接口中定义,其API说The class that implements this interface defines how the object is written 。 这意味着理论上可能会有除ObjectOutputStream以外的其他实现,这些实现可能使用了其他不需要Serializable对象的序列化方式。

writeObject is defined in ObjectOutput interface and its API says The class that implements this interface defines how the object is written. It means that theoretically there may be implementations other than ObjectOutputStream which may be using other ways of serialization which do not require the object be Serializable.

更多推荐

本文发布于:2023-07-23 01:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   writeObject   Java   Object   Serialization

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!