Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of java.io.Serializable class?

In "Layman's" terms I was wondering if someone could explain to me the significance and general importance of importing the Serializable class to implement the java.io.Serializable interface. asked from java student

like image 466
java_threads Avatar asked Apr 02 '11 01:04

java_threads


1 Answers

java.io.Serializable is what is known as a "marker interface". The interface itself has no methods defined in it. So any class can easily implement this interface by simply implementing it:

 public class MyClass implements Serializable {
       public void aMethodForMyClass() { }

       // not implementing any specific java.io.Serializable methods because
       // the interface has no methods to implement.
 }

It is a "marker" interface because by implementing this interface you are telling the Java serializer that it is OK to serialize objects of this type. If your class does not implement this interface, the serializer will refuse to serialize any objects of that type.

like image 113
Matt Greer Avatar answered Oct 20 '22 06:10

Matt Greer