Pergunta

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 ?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top