1.5. Object Streams and Serialization
Using a fixed-length record format is a good choice if you need to store data of the same type. However, objects that you create in an object-oriented program are rarely all of the same type. For example, you might have an array called
staff that is nominally an array of
Employee records but contains objects that are actually instances of a subclass such as
It is certainly possible to come up with a data format that allows you to store such polymorphic collections—but fortunately, we don’t have to. The Java language supports a very general mechanism, called object serialization, that makes it possible to write any object to a stream and read it again later. (You will see later in this chapter where ...