CuriousGuy CuriousGuy - 1 month ago 5
Java Question

Serialization not implemented?

What I understand is that I can implement

Serializable
interface to make my object seriazable.

But I don't get where is
writeObject
implemented when
Serializable
is an interface, so it doesn't contain implementation of methods, just a definition?

Answer

As you already noticed, the Serializable is a Marker Interface and does not have any methods to implement. Implementing Serializable is just a note that this one is eligible for serialization which is handled using ObjectOutputStream.

Methods you mentioned need to be implemented in a class implementing the Serializable interface and will be picked up automatically. Since there is no obligation for implementing them, they are not included in the interface.

http://docs.oracle.com/javase/8/docs/platform/serialization/spec/serial-arch.html#a4539