Java Serialization, writeObject(Object obj) why not writeObject(Serializable obj)
Asked Answered
G

1

8

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 ?

Gilchrist answered 17/6, 2013 at 9:48 Comment(0)
K
7

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.

Kalpak answered 17/6, 2013 at 9:56 Comment(1)
what are other way to serialize, apart from Externizalbe?Tormentor

© 2022 - 2024 — McMap. All rights reserved.