views:

670

answers:

5

I need a list of classes that implement Serializable. Could you also tell me what kind of classes implement that interface?

+2  A: 

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.

jjnguy
+9  A: 

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.

Esko Luontola
+1 for posting the class-use before I could.
Michael Myers
+1  A: 

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.

Cuga
You can also use the Menu: Navigate > Quick Type Hierarchy.
Cuga
Why would you vote this down? It gives a full list of all the classes on your classpath that implement Serializable, and this is a much more comprehensive list than the ones given above.
Cuga
I guess you got the downvotes because you suggested making a class just for the sake of being able to select the Serializable interface. I would suggest accessing the interface by hitting Ctrl + Shift + T, and typing Serializable into the filter box. After that, you can either hit the above mentioned Ctrl + T to get the class hierarchy in a floating widget, or F4 to get it in a separate view.
Zsolt Török
I see what you mean. I didn't intend to imply this was the only way to open the type hierarchy-- I wanted it to be easy and clear to see how it can done.
Cuga
The original question was for "a list of classes that implement Serializable". What list? Serializables in the JDK? Serializables in a large mess of code you've just inherited? Either interpretation is reasonable, and learning how to look up the information in both situations is helpful.
Jim Ferrans
A: 

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.

Tom Hawtin - tackline
A: 

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.

R. Bemrose
Serialization is *not* for long-term storage. Only for short-term uses such as communication.Classes that implement Externalizable do store their externalised state in the serialization stream. The difference between serialisabke and exrernalisable classes is that the serialiser is responsible for the stream format of serialisable classes but externalisable classes implement their own format.
Nat
Sorry for the typos: I wrote it on an iPhone.
Nat