Why does ObjectOutputStream.writeObject(Object o)
not take a Serializable
? Why is it taking an Object
?
This is because writeObject
in ObjectOutputStream
overrides the method in the ObjectOutput
interface which does not require that the object be Serializable
.
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.