Java Reference
In-Depth Information
< Day Day Up >
14. Serialization
This section concerns Java's object serialization system.
14.1. Making a class serializable introduces a public pseudoconstructor
Prescription: Think twice before making a class serializable.
Think twice before accepting the default readObject method.
Write readObject methods defensively.
References: [EJ Items 54 and 56].
14.2. The serialized form is a part of a class's public API
Prescription: Design serialized forms with the same care that you would design any other API.
Reference: [EJ Items 54 and 55].
14.3. Using the default serialized form leaks private fields into a class's
public API
Prescription: Consider using a custom serialized form.
References: [EJ Item 55].
14.4. Using the default serialized form can cause poor performance
Prescription: Consider using a custom serialized form.
References: [EJ Item 55].
14.5. Maintaining instance-control invariants requires a readResolve
method
Prescription: Always write a readResolve method for singletons, handwritten Typesafe Enums,
and other instance-controlled instantiable classes.
References: Puzzle 83 ; [EJ Items 2 and 57].
 
 
Search WWH ::




Custom Search