0

I know that the implementation of the interface Serializable makes an object to be serialized, but how is possible that when the interface is simply a definition of a class with their methods like:

interface Serializable {
   public one();
   public two();
}

public class Dog implements Serializable {
private static final long serialVersionUID = 1L;
  ...
}

(class Dog doesn't implement any method of Serializable)

Simply I don't understand, can you explain me?

BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
  • Serializable is a marker interface. Try a google search for "marker interface". – DwB Mar 14 '16 at 20:43

1 Answers1

2

The reason is because the interface has no method...

Why not?

because the interface is defined as a 'marker interface'.

What is that??:

the interface is used only to TAG objects so that the JVM can get more information about them at runtime

if you have the chance, take a look at the Effective java from Joshua Bloch:

Quote:

A marker interface is an interface that contains no method declarations, but merely designates (or “marks”) a class that implements the interface as having some property.

For example, consider the Serializable interface (Chapter 11). By implementing this interface, a class indicates that its instances can be written to an ObjectOutputStream (or “serialized”)....

user207421
  • 298,294
  • 41
  • 291
  • 462
ΦXocę 웃 Пepeúpa ツ
  • 45,713
  • 17
  • 64
  • 91