I need a list of classes that implement Serializable. Could you also tell me what kind of classes implement that interface?
You can find a full list of all implementing classes Here.
If you need to check programatically, you can use the instanceof
operator to check to see if an object is an instance of the Serializable
interface.
The list of subinterfaces is not a list of all classes that actually implement the interface.
In the Java API, most of the classes implement Serializable (here is a full list). Classes that need to be serialized implement Serializable. You can use an IDE to find all implementors of an interface in your project.
If you use Eclipse, then in any place you see "Serializable" (such as in the class definition below):
import java.io.Serializable;
public Foo implements Serializable {
}
- Click on
Serializable
so that the text marker is in the word - Hit Control + T
It should take a minute because this is such a prevalent interface, but it will display all the classes it can find on your classpath which implement Serializable
.
Implementing Serializable
effectively makes classes and subclasses part of the public API. You can see at least some of the serialisable classes by clicking on the Serial Form link in Javadoc output. Some of these classes are not public/protected as such (in the API docs they wont have links to the class documentation). Serialisable anonymous inner classes don't appear to appear, although there are a few this$0
fields.
The quick answer is: Any class that you want to store for later use.
This includes things like the data wrappers (Integer, String, Character, etc...), data classes, and Collections.
However, Collections are only serializable if the items in them are serializable.
Also, there is a second interface, Externalizable, that is used by classes that write their data to some sort of external interface, with only a reference to said item stored in the serialization stream.