Are classes that implement Serializable required to have no-argument constructors?
Location: http://www.jguru.com/faq/view.jsp?EID=251942 Created: Nov 12, 2000 Modified: 2000-12-21 16:46:34.173 Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) No. This is a common misconception. The deserialization process does not use the object’s constructor – the object is instantiated without a constructor and initialized using the serialized instance data. The only requirement on the constructor for a class that implements Serializable is that the first non-serializable superclass in its inheritence hierarchy must have a no-argument constructor. (See http://www.jguru.com/jguru/faq/view.jsp?EID=34802 for a more complete explanation). This makes sense: deserialization needs to reconstruct the entire object state, which includes the state of any superclasses. If the superclass is not itself serializable, then deserialization needs to instantiate that superclass from scratch – thus the requirement. For example, with the following class: public class MySerializableCla