javaobjectoutputstream

Does writeObject(Object obj) write the whole class of the object?


Regarding the method writeObject(Object obj) from ObjectOutputStream class

From Javadocs:

Write the specified object to the ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written.

What does the Statement

The class of the object

mean? Does that mean that the .class File is writen to the file or the source code of the class or only the name of the class?


Solution

  • The name of the class, so that when the ObjectInputStream reads it back in it knows what class to instantiate. It doesn't need the source code of the class, just its name.