Java Reference
In-Depth Information
perform a deeper clone whenever a shallow clone is not appropriatesuch
as in the
IntegerStack
example.
entire object graphs to a stream of bytes and, using that generated
stream of bytes, create an equivalent copy of the original object graphs.
Serialization can provide a way to make deeper copies than those
provided by
Object.clone
.
Exercise 3.8
: Make
Vehicle
and
PassengerVehicle
into
Cloneable
types.
Which of the four described attitudes should each class take toward
cloning? Is the simple copying done by
Object.clone
correct for the clone
methods of these classes?
Exercise 3.9
: Write a
Garage
class whose objects can hold up to some
number of
Vehicle
objects in an array. Make
Garage
a
Cloneable
type, and
write a proper
clone
method for it. Write a
Garage.main
method to test it.
Exercise 3.10
: Make your
LinkedList
class (from the exercises in
same values as the original list, not clones of the values. In other words,
changes to one list should not affect the other list, but changes to the
objects referenced by the list would be visible in both lists.