giannis christofakis
giannis christofakis

Reputation: 8321

Why classes that implements Serializable interface implements none interface's methods?

I thought class that implements an interface must implement all of the interface's methods,why classes that implements Serializable interface implements none interface's methods ?

Upvotes: 0

Views: 401

Answers (2)

Krystian Cybulski
Krystian Cybulski

Reputation: 11118

Some interfaces act simply as markers for classes. Serializable is one of them. The methods are there only in case your object requires special handling in order to be serialized and deserialized.

Upvotes: 3

Tudor
Tudor

Reputation: 62459

Because Serializable is only a "marker" interface for object serialization and has no methods defined. From the Javadoc:

The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

And from SDN:

An object is marked serializable by implementing the java.io.Serializable interface, which signifies to the underlying API that the object can be flattened into bytes and subsequently inflated in the future.

Upvotes: 3

Related Questions