Why does ObjectOutputStream.writeObject not take a Serializable?

前端 未结 2 799
离开以前
离开以前 2020-12-28 15:45

Why does ObjectOutputStream.writeObject(Object o) not take a Serializable? Why is it taking an Object?

2条回答
  •  伪装坚强ぢ
    2020-12-28 16:26

    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.

提交回复
热议问题