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 IOExceptionAs obj should implements Serializable (know about markers). Why java developers do not write this method as
public final void writeObject(Serializable obj) throws IOExceptionis 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.
更多推荐
发布评论